함수를 호출하려고하는데 정의되지 않은 함수라는 오류가 발생합니다.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);
}
});
어디서 잘못 될지 모르겠습니다. 도와주세요.
getNodeId: function(){
var self = this;
objectJSON = jAccess.getJSON();
nodeIdArray = []
_.each(objectJSON, function(action){
_.each(action.Nodes, function(action){
nodeIdArray.push(action.Id);
self.getAction();
});
});
},
I을 :
나는, 당신이 할 수있을 것입니다 간단한 수정으로 평가 기능 ('this.getAction()')
이것은 아마도 범위 문제 일 수 있습니다. getNodeId()의 시작 부분과 this.getAction() 이전의 행에서 루트 객체 console.log (this)의 값은 무엇입니까? 일치하지 않으면 범위 지정 문제가됩니다. – Gazler
잘 모르겠습니다. 나는 확인해야 할 것이다. – JABD
'this.getAction() '앞에 DOMWindow가 있습니다. – JABD