모든 스크립트가로드되었지만 모델이 백본으로 정의되지 않은 것으로 보이는 백본에서이 문제가 발생합니다. (백본 및 기타 javascript 파일을로드하려면 require를 사용하고 있습니다). 나는 collection.fetch을 할 때마다백본 targetModel = 정의되지 않음
그래서 내가 불을 지르고에서이 오류를 얻을 :
TypeError: targetModel is undefined
나는이 시점에서 보유하고있는 스크립트를 실행하면 :
if (attrs instanceof Model) {
id = model = attrs;
} else {
id = attrs[targetModel.prototype.idAttribute];
}
내 마우스를 가져가 over targetModel 그것은 말합니다 : 정의되지 않았습니다 어떻게 든 지금은 작동하지 않는 것 그리고 유일한 일은 collection.fetch 후에로드되는 HTML 템플릿을 변경하는 것입니다.
여기 좀 도와주세요. 이 필요한 부분
var OF = OF || {};
OF.UsersCollection = Backbone.Collection.extend({
initialize: function() {
//
},
parse: function(data){
return data["all-users"];
},
model: OF.UsersMdl,
url: 'php/api/users'
});
그리고 마지막으로 라우터 : 여기
goToUsers: function() {
require(['./models/users', './views/users_view', './collections/user_collection'], function(UsersMdl, UsersView, UsersCollection) {
OF.usersMdl = new OF.UsersMdl;
OF.usersCollection = new OF.UsersCollection;
OF.usersView = new OF.UsersView;
//when the collection is fetched
$.when(OF.usersCollection.fetch({
data: {
"admin": OF.login.attributes.admin,
"session": OF.login.attributes.session
},
success: function(){
//console.log(OF.usersCollection.length);
}
//then render the view
})).then(function(){
OF.usersView.render();
}, 300);
});
},
가 여기있다
var OF = OF || {};
OF.UsersMdl = Backbone.Model.extend({
default: {
username: '',
mailinglist: '',
email: ''
},
initialize: function() {
//
},
result: {
success: false,
message: ''
},
validate: function(att) {
}
});
컬렉션입니다 : 여기
내 모델입니다 가져 오기로 복구 할 JSON :
{ "모든 사용자" [ { "사용자 이름": "테스터", "메일 링리스트": "1", "이메일": "[email protected]" }, { "이름": "tester2" "메일 링리스트": "1", "이메일": "[email protected]" }, { "사용자 이름": "tester3" "메일 링리스트": "0 ", "email ":"[email protected] " } ] }
미리 감사드립니다.
'targetModel '은 어디에 정의되어 있습니까? – fbynite
targetModel은 백본 변수입니다. 그래서 저는 이것을 정의하지 않습니다. 컬렉션의 "model : OF.UsersMdl"부분을 의미하지 않는다면? – BonifatiusK
개인적으로 'targetModel'기본 변수에 대해 들어 본 적이 없으므로 문서에 대한 링크를 게시 할 수 있습니까? – drax