楷模
Network.Models.FeedItem = Backbone.Model.extend({
isPost: function() {
return this.get('template') === 'post';
}
})
Network.Models.Post = Backbone.Model.extend({
urlRoot: '/p',
hasImageInDetails: function() {
if(this.get('details').match(/<img[^<]*>[\w\d]*<\/img>|<img[^\/]*\/>/i)) {
return true
}
}
)}
模板
feed_items/post.jst.eco
<% if @model.hasImageInDetails(): %>
has image
<% end %>
意见
Network.Views.FeedItemView = Backbone.View.extend({
initialize: function() {
var self = this;
this.template = JST[this.path()];
},
render: function() {
var self = this;
$(this.el).html(this.template({ model: this.model }));
if (this.model.isPost()) {
this.questionView = new Network.Views.FeedItems.Post({
model: this.model,
el: this.$el,
parent: this
});
}
}
});
Network.Views.FeedItems.Post = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
var self = this;
}
});
但我收到一个错误:
Uncaught TypeError: Object [object Object] has no method 'hasImageInDetails'