我现在不仅想找到解决此问题的方法,还想了解为什么它不起作用。
假设我在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>
好的,您可以在我的小提琴上确认这是行不通的:
但是问题是为什么不呢?
值得一提的是,它没有数据列表也可以正常工作:
尝试这样。我更改了您的filter
函数语法,还添加了select
标记dataList
。
编辑:您的问题的原因为datalist
id。即您的datalist
IDne-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] 删除。
我来说两句