Muh*_*iaz 4 javascript jquery loops limit angularjs
AngularJS
userData.success(function (userdataobject) {
$scope.catadata = userdataobject;
$scope.quantity = 1;
});
userData.success(function (userdataobject) {
$scope.catadata1 = userdataobject;
$scope.quantity1 = 1;
});
Run Code Online (Sandbox Code Playgroud)
AngularJS 2不同的循环代码
环1
<div ng-repeat="cat in catadata | limitTo:quantity | filter: {TopCategoryID : 11}">
Run Code Online (Sandbox Code Playgroud)
回路2
<div ng-repeat="cat1 in catadata1 | limitTo:quantity1 | filter: {TopCategoryID : 12}">
Run Code Online (Sandbox Code Playgroud)
limitTo:quantity
正在工作,但limitTo:quantity1
没有工作
TLDR:你必须将limitTo
过滤器移到最后:
<div ng-repeat="cat1 in catadata1 | filter: {TopCategoryID : 12} | limitTo:quantity1">
Run Code Online (Sandbox Code Playgroud)
该limitTo
过滤器会创建具有所需长度的新数组,那么您的过滤器将被应用,可以这样考虑:
var catadata1 = [
{TopCategoryID: 13, ...},
{TopCategoryID: 42, ...},
{TopCategoryID: 12, ...},
...
];
// When we apply the limitTo, this is what's happening:
var limitTo = catadata1.slice(0, 1); // Keep the first item
// And when we apply the filter we only filter on the limitTo array:
var filter = limitTo.filter(matchItem({TopCategoryID : 12}));
Run Code Online (Sandbox Code Playgroud)
另一种观察方式是:
var a = [0, 1, 2]; // Initial Array
var b = [0] // limitTo: 1
var c = [] // filter: 2
Run Code Online (Sandbox Code Playgroud)
而:
var a = [0, 1, 2]; // Initial Array
var b = [0] // limitTo: 1
var c = [0] // filter: 0
Run Code Online (Sandbox Code Playgroud)
这是您的代码中发生的事情,只是使用另一个过滤器.
归档时间: |
|
查看次数: |
2716 次 |
最近记录: |