在两个单独的数组上嵌套ng-repeat

达洛佐

我现在不仅想找到解决此问题的方法,还想了解为什么它不起作用。

假设我在angular中有这个数组:

 $scope.movieThemes = [ 'Fiction', 'Drama'];

另一个带有电影的数组,例如:

$scope.movies=[{theme:'Drama', movie:'One million dollar baby'}, {theme:'Drama', movie:'Green mille'},{theme:'Fiction', movie:'Avatar'}, {theme:'Fiction', movie:'The Hobbit'}]

我的主题有一个ngRepeat

<div ng-repeat= "t in movieThemes">

还有一个嵌套的数据列表,用于过滤主题:

ng-repeat="m in movies|filter:{theme:t}

其中t来自父转发器,例如:

 <datalist id="movieList">
    <option ng-repeat="m in movies|filter:{theme:t}" value="{{m.movie}} - {{t}}"></option>
  </datalist>

好的,您可以在我的小提琴上确认这是行不通的:

在线演示

但是问题是为什么不呢?

值得一提的是,它没有数据列表也可以正常工作:

没有数据列表演示

哈迪J

尝试这样。我更改了您的filter函数语法,还添加了select标记dataList

编辑:您的问题的原因为datalistid。即您的datalistIDne-repeat是相同的。datalist通过添加更改ID $index现在它可以正常工作了。

var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', ["$scope",function MyCtrl($scope) {
   $scope.movieThemes = [ 'Fiction', 'Drama'];
$scope.movies=[
  {theme:'Drama', movie:'One million dollar baby'},
  {theme:'Drama', movie:'Green mille'},
  {theme:'Fiction', movie:'Avatar'}, 
  {theme:'Fiction', movie:'The Hobbit'}
];
  

}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
  <div ng-repeat= "t in movieThemes">
  <input  type="text" ng-model="t"  />
  {{t}} - {{$index}} <input type="text"  placeholder="Users" list="movieList{{$index}}">
     <datalist id="movieList{{$index}}">
        <select>
            <option  ng-repeat="m in movies|filter:{theme:t}" value="{{m.movie}} - {{t}}"></option>
         </select>
     </datalist>
  </div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章