我想調用一個函數,但我得到一個錯誤,說明函數未定義。Backbone.View無法調用函數
window.PackageView = Backbone.View.extend({
tagName: "div",
className: "package-template",
events:{
"click #display-name" : "getNodeId",
},
initialize: function() {
_.bindAll(this,'render', 'getNodeId', 'getAction');
this.template = _.template($('#package-template').html());
$(this.el).html(this.template); //Load the compiled HTML into the Backbone "el"
nodeInstance.bind('reset', this.render, this);
},
render: function() {
//.. no need to worry about this.
},
getNodeId: function(){
objectJSON = jAccess.getJSON(); // I get the JSON successfully
nodeIdArray = []
_.each(objectJSON, function(action){
_.each(action.Nodes, function(action){
nodeIdArray.push(action.Id);
this.getAction(); // Here is the problem. I get an error
});
});
},
getAction: function(){
actionsArray = [];
objectJSON = jAccess.getJSON();
_.each(objectJSON, function(action){
_.each(action.Nodes, function(action){
if(action.Id == 5) {
_.each(action.Actions, function(action){
actionsArray.push(action.Name);
});
}
});
});
console.log(actionsArray);
}
});
我不知道我在哪裏會出錯。幫幫我。
我得到一個錯誤說「未定義」不是評價一個函數(「this.getAction()」)
這可能是一個範圍問題。根節點console.log(this)在getNodeId()的開始處和this.getAction()之前的行的值是什麼?如果它們不匹配,那麼它肯定是一個範圍問題。 – Gazler
我不知道。我將不得不檢查。 – JABD
它在'this.getAction()'之前說DOMWindow' – JABD