저는 Backbone보기의 간단한 상속 계층 구조를 가지고 있으며 내 모든보기에 하나의 일반 모델이 있어야합니다. 이러한 뷰에서 모델의 url 속성 만 달라집니다. 그래서 모델을 초기화 할 때 url을 전달합니다.url 속성을 모델에 전달하면 작동하지 않습니다.
GenericView = Backbone.View.extend({
template: "friendsList-template.html",
initialize: function(){
var that = this;
that.model.fetch({
success: function(model,response){
that.handleResponse(response);
},
error: function(){
//handle error
}
});
}
});
그리고 아이 뷰는 다음과 같습니다 :
부모 일반적인 전망이다
PersonView = GenericView.extend({
el:$("#container"),
personData: {},
template: "profile-template.html",
model = new GenericModel({
url:"testRouter.php"
});//here is where I'm defining the url
initialize: function(){
PersonView.__super__.initialize.apply(this);
},
render: function(){
var that = this;
$.get(this.templatesPath + this.template, function(resTemplate){
var html = Mustache.render(resTemplate, that.personData);
that.$el.html(html);
});
},
handleResponse: function(res){
this.personData = res;
this.render();
}
});
그리고 GenericModel는
GenericModel = Backbone.Model.extend({
});
(지금 이상에 대한) 단순히 비어있는 모델입니다 콘솔에서 다음 오류가 발생합니다 :
Uncaught Error: A "url" property or function must be specified backbone.js:1559
내 계층 구조가 문제입니까? 이견있는 사람? fine manual에서
, 나는이 일을 시도하고 편집 할 수 있었다 및 코드의 잘못된 버전을 붙여 –