我的使用angularJS,和具有2點陣列如下面angularJS第二陣列的更新陣列基本值
$scope.varStr = [{"subjectId":"1","subjectShortName":"English"},
{"subjectId":"2","subjectShortName":"French"},
{"subjectId":"3","subjectShortName":"German"},
{"subjectId":"4","subjectShortName":"Latin"},
{"subjectId":"5","subjectShortName":"English-Aus"}
];
$scope.varStr2 = [{"subjectId":"1","subjectShortName":"English"},
{"subjectId":"5","subjectShortName":"English-Aus"}
];
基地類似值的$ scope.varStr2,UPDATE $ scope.varStr subjectId或創建新的$範圍.varStr3如下面新的關鍵「IsSelected」:真/假
$scope.varStr3 = [{"subjectId":"1","subjectShortName":"English","IsSelected": true},
{"subjectId":"2","subjectShortName":"French","IsSelected": false},
{"subjectId":"3","subjectShortName":"German","IsSelected": false},
{"subjectId":"4","subjectShortName":"Latin","IsSelected": false},
{"subjectId":"5","subjectShortName":"English-Aus","IsSelected": true}
];
for (var index = 0; index < varStr.length; index++) {
if (varStr[index].subjectId == varStr2[index].subjectId) {
varStr.push("'IsSelected':'true'");
}
}
這與AngularJS無關。這是一個純粹的JavaScript /算法問題。你有嘗試過什麼嗎?你面臨什麼困難?或者你只是想讓我們爲你寫代碼? –
代碼添加。錯誤是'subjectId'未定義 – fresher
也試圖實現從angularJS.extend – fresher