是否可以选择从head -n5 file1 | parallel -a - -j 4 echo #this works
head -n5 file1 | parallel -a - -j 4 ./myscript #this doesn't
过滤数组$scope.items
中存在 ID 的地方?
$scope.myitems
演示:http://codepen.io/anon/pen/rOeGYB
ng-repeat="item in items | filter:{item.id == myitems}
angular.module('myapp', [])
.controller("mycontroller", function($scope) {
$scope.items = [
{
"id": 1,
"name": "Melodie"
}, {
"id": 2,
"name": "Chastity"
}, {
"id": 3,
"name": "Jescie"
}, {
"id": 4,
"name": "Hamish"
}, {
"id": 5,
"name": "Germaine"
}, {
"id": 6,
"name": "Josephine"
}, {
"id": 7,
"name": "Gail"
}, {
"id": 8,
"name": "Thane"
}, {
"id": 9,
"name": "Adrienne"
}, {
"id": 10,
"name": "Geoffrey"
}, {
"id": 11,
"name": "Yeo"
}, {
"id": 12,
"name": "Merrill"
}, {
"id": 13,
"name": "Hoyt"
}, {
"id": 14,
"name": "Anjolie"
}, {
"id": 15,
"name": "Maxine"
}, {
"id": 16,
"name": "Vance"
}, {
"id": 17,
"name": "Ashely"
}, {
"id": 18,
"name": "Dominic"
}, {
"id": 19,
"name": "Cora"
}, {
"id": 20,
"name": "Bo"
}
];
$scope.myitems = ['0', '3', '6', '10', '19']
});
答案 0 :(得分:10)
您的问题是您正在尝试匹配您正在迭代的对象的子属性。
来自文档:
请注意,命名属性将匹配同一级别的属性 只有,而特殊的$属性将匹配相同的属性 等级或更深。例如。一个数组项,如{name:{first:' John',last: ' Doe'}}将不会被{name:' John'}匹配,但将被匹配 {$:' John'}。
我建议您自定义过滤器。 我已经通过实现自定义过滤器,您的需求的工作副本来更改您的代码。
<li class="list-group-item" ng-repeat='item in items | customArray:myitems:"id"'>{{item.name}}</li>
在此处查看完整的plunker https://codepen.io/anon/pen/PPNJLB
答案 1 :(得分:7)
使用此答案的优秀过滤器:
https://stackoverflow.com/a/21171880/2419919
.filter('inArray', function($filter){
return function(list, arrayFilter, element){
if(arrayFilter){
return $filter("filter")(list, function(listItem){
return arrayFilter.indexOf(listItem[element]) != -1;
});
}
};
});
答案 2 :(得分:0)
angular.forEach($scope.items, function (v, k) {
console.log($scope.myitems[v.id - 1]);
$scope.myitems[v.id- 1].name = v.name;
}, $scope.myitems);
只是为了一些提示。希望帮助
答案 3 :(得分:0)
上面的例子由Kashif Mustafa给出完美的作品。 我们唯一需要做的改变是将字符串解析成整数。
CSHTML:
var eIds = detail.entityIds;
var eArray = eIds.split(",");
if (eArray.length > 0) {
$scope.showEntities = true;
$scope.showNone = false;
for (var i = 0; i < eArray.length; i++) {
$scope.SelectedEntities.push(parseInt(eArray[i]));
}
}
控制器:
(your controller).filter('customArray', function ($filter) {
return function (list, arrayFilter, element) {
if (arrayFilter) {
return $filter("filter")(list, function (listItem) {
return arrayFilter.indexOf(listItem[element]) != -1;
});
}
};
});
过滤器:
js