admin管理员组文章数量:1352266
I hope i can abstract all the relevant parts. My question is why the render method isn't executing when i fetch my model from the server.
Model
var Document = Backbone.Model.extend({
urlRoot: "/dms/reconcile/GetDocumentByDocumentId/"
});
View
window.DocumentView = Backbone.View.extend({
el: $("#reconcile_document"),
initialize: function () {
this.model.bind('refresh', this.render) //also tried reset
},
render: function () {
alert("Do awesome stuff here");
return this;
}
});
Route
var AppRouter = Backbone.Router.extend({
routes: {
"package/:id": "getPackage"
},
getPackage: function (packageid, p) {
window._document = new Document({ id:packageid) });
window.document = new DocumentView({ model: _document });
_document.fetch();
}
});
// Instantiate the router
var app_router = new AppRouter;
So when i go to localhost:3000/#/Package/123
I can see that the xhr call to localhost:3000/dms/reconcile/GetDocumentByDocumentId/123
and the data es back successfully but the render
function never executes. Any help would be greatly appreciated.
Cheers.
I hope i can abstract all the relevant parts. My question is why the render method isn't executing when i fetch my model from the server.
Model
var Document = Backbone.Model.extend({
urlRoot: "/dms/reconcile/GetDocumentByDocumentId/"
});
View
window.DocumentView = Backbone.View.extend({
el: $("#reconcile_document"),
initialize: function () {
this.model.bind('refresh', this.render) //also tried reset
},
render: function () {
alert("Do awesome stuff here");
return this;
}
});
Route
var AppRouter = Backbone.Router.extend({
routes: {
"package/:id": "getPackage"
},
getPackage: function (packageid, p) {
window._document = new Document({ id:packageid) });
window.document = new DocumentView({ model: _document });
_document.fetch();
}
});
// Instantiate the router
var app_router = new AppRouter;
So when i go to localhost:3000/#/Package/123
I can see that the xhr call to localhost:3000/dms/reconcile/GetDocumentByDocumentId/123
and the data es back successfully but the render
function never executes. Any help would be greatly appreciated.
Cheers.
Share Improve this question asked Oct 21, 2011 at 23:56 Amin EshaqAmin Eshaq 4,0241 gold badge19 silver badges21 bronze badges1 Answer
Reset to default 8Calling fetch()
on a model won't fire a refresh
event. It will fire a change
event by calling set
after it fetches the data:
http://documentcloud.github./backbone/docs/backbone.html#section-40
and
http://documentcloud.github./backbone/#Model-fetch
Change your event handler and it should work:
window.DocumentView = Backbone.View.extend({
el: $("#reconcile_document"),
initialize: function () {
this.model.bind('change', this.render, this);
},
render: function () {
alert("Do awesome stuff here");
return this;
}
});
本文标签: javascriptBackbone Model Fetch refresh event not firingStack Overflow
版权声明:本文标题:javascript - Backbone Model Fetch refresh event not firing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743912271a2560613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论