元素在我的骨幹觀點正確的方法,我正在從我收集的模型..什麼是擺脫集合
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'
})
}
});
如何我添加類名ŧ o這li
元素中的每一個?這裏有什麼錯,任何人都可以幫我排序,或者可以給我一個正確的方法來過濾一個集合並將類名應用到它的元素中?
烏盧格別克Komilovich - 你爲什麼刪除jsfiddle? – 3gwebtrain 2013-04-27 13:59:42
您在調用showMe函數之前/之前沒有調用渲染 – 2013-04-27 14:08:34
我很抱歉無法正確更改,我確實在更改您的時間進行更改 – 2013-04-27 14:10:42