![](/img/trans.png)
[英]Several elements use the same css class, how can I change the css properties of only one of those elements
[英]How to change css properties of several elements associated with models in a Backbone collection?
会做点什么
m.set('background-color', 'green') for m in @model.collection.where(selected: true)
然后可能以某种方式渲染属性?
这样的事情可能吗?
m.$el.css('opacity', 1) for m in @model.collection.where(selected: true)
理想情况下,您应该定义一个视图并将其绑定到模型中的change事件,这样无论何时在模型上更新属性,您的视图都会相应地更新,例如:
var myView = Backbone.View.extend({
initialize : function() {
myModel.bind('change', render);
},
render: function() {
$("#myElement").css('opacity', myModel.isSelect ? 1 : 0)
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.