我有兩個數組,如果條件滿足,我必須推入新數組$ scope.checkData.I中的匹配對象必須從$ scope.checkData中獲取函數中的「val」並檢入$ scope .postData如果條件退出,如何推入新數組?
的Javascript:
$scope.postData= [
{ "pid": 1, "id": 1, "status": 1 },
{ "pid": 1, "id": 2, "status": 0 },
{ "pid": 1, "id": 3, "status": 1 },
{ "pid": 1, "id": 4, "status": 1 },
{ "pid": 1, "id": 5, "status": 0 },
{ "pid": 1, "id": 6, "status": 1 },
{ "pid": 1, "id": 7, "status": 1 }
];
$scope.checkData= [
{ "val": 1, "txt": "one" },
{ "val": 2, "txt": "two" },
{ "val": 3, "txt": "three" },
{ "val": 4, "txt": "four" },
{ "val": 5, "txt": "five" },
{ "val": 6, "txt": "six" },
{ "val": 7, "txt": "seven"
}];
$scope.bindData = function (id) {
console.log(id);
$scope.someAry = [];
id.forEach(function (elem) {
$scope.postData.forEach(function (val) {
console.log(elem);
if (val.id== elem && val.status == true) {
alert("match found");
}
else {
alert("match not found");
}
});
在此先感謝。
請添加想要的結果。 –
@ Nina Scholz我更新了預期結果的問題,請檢查一次後請給我。 – pbsbr