在我的主干视图中,我正在从我的收藏中获取模型..
initialize:function(){
this.collection = new collection(student);
this.render();
},
从这个集合中,我使用过滤器方法过滤高价值模型:(点击我触发)
getHighSocre:function(){
return _.filter(this.collection.models, function(item){
return parseInt(item.get('scored')) > 60
})
},
showHighScore:function(){
var hView = new studentView({model:this.getHighSocre()}); // sending to single view
hView.showMe(); // I am calling this method to add a class name to each 'li' element..
}
这是我的单一观点:
var studentView = Backbone.View.extend({
tagName:'li',
events:{
'click':"called"
},
template:_.template($("#studentTemplate").html()),
render:function(){
this.$el.append(this.template(this.model.toJSON()));
return this;
},
called:function(){
if(this.model.get('scored') > 60){
this.$el.css({
background:"#EFEFEF"
})
}else{
this.$el.css({
background:"#FCBABA"
})
}
},
showMe:function(){ // I am passing here to add a class name
console.log(this) // make the array... here
this.$el.css({ // but this is not getting the dom element...
border:'1px solid red'
})
}
});
如何将类名添加到每个li
元素?这里有什么问题,任何人都可以帮助我进行排序,或者可以给我一个正确的方法来过滤集合并将类名应用于它的元素?