В моя основен изглед получавам модели от моята колекция..
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
елемента? Какво не е наред тук, някой може да ми помогне да сортирам или може да ми даде правилен начин да филтрирам колекция и да приложа името на класа към нейния елемент?