我想在指令中創建一個指向特定部分json對象的$ watch,但它似乎並不接受語法(不會出現錯誤,但它永遠不會出現在手錶內部)
link: function (scope, element) {
scope.JsonObject={
profs:{
prof1:[{
name:example1a,
id:example1b
}],
prof2:[{
name:example2a,
id:example2b
}]
}
}
scope.teachers=scope.JsonObject['profs']
//until here all ok
for (var teacher in scope.teachers){
//stuff to do
console.log("creating watch of " + teacher);
scope.$watch('teachers[teacher]', function() { //here seems to be the problem (it doesnt seem to accept JsonObject.teacher)
//stuff to do
}, true);
}
你想達到什麼做創建指令裏面的手錶,請說清楚,並與您的代碼plunkr將有助於解決您的問題 –
我要做的就是調用highcharts插件: 新Highcharts.chart(老師+「_id」,chartoptions); 但在這種情況下,我不認爲它是相關的,問題是它永遠不會進入手錶 –
'JsonObject.teacher'是'undefined'因此您可以使用'JsonObject.profs'或'teacher.profs' –