考虑遵循模型和视图。我想知道为什么以下指示的行不起作用?
var app = app || {};
(function () {
app.CurrentUserView = Backbone.View.extend({
el: $('.avatar-container'),
template: ux.template('.avatar-container-hbs'),
initialize: function () {
this.model = new app.User();
this.model.fetch();
x=this.model;
//these two lines output expected values.
console.log(this.model);
console.log(this.model.toJSON());
this.render();
},
// Re-render the titles of the post item.
render: function () {
//this does not work! (empty)
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
})();
模型:
var app = app || {};
(function () {
'use strict';
app.User = Backbone.Model.extend({
url:'api/user.php'
});
})();