Backbone.js 主干及;jQuery Tmpl-将样式应用于模板项

Backbone.js 主干及;jQuery Tmpl-将样式应用于模板项,backbone.js,jquery-templates,Backbone.js,Jquery Templates,我的主干视图如下所示,使用jQuery tmpl库呈现。我想将样式应用于其中的一个/所有/任何数据项 活动==1。有什么办法吗 // backbone view window.CaseView = Backbone.View.extend({ el: $("#main"), initialize: function() { _.bindAll(this, 'render'); this.render(); },

我的主干视图如下所示,使用jQuery tmpl库呈现。我想将样式应用于其中的一个/所有/任何数据项 活动==1。有什么办法吗

   // backbone view 
   window.CaseView = Backbone.View.extend({

    el: $("#main"),

    initialize: function() {
        _.bindAll(this, 'render');
        this.render();
    },

    iTemplate: $("#tmplCase").template(),

    render: function() {
        var that = this;
        that.el.fadeOut('fast', function() {
            $.tmpl(that.iTemplate, that.model.toJSON()).appendTo(that.el);
            that.el.fadeIn('fast');
        });

        return this;
    }
});

// html file
<div id="main"></div>

<script id="tmplCase" type="text/x-jquery-tmpl">
  <div class="caseInActive">
    <span class="title">${title}</span>
    <span class="current_status">${active}</span>
  </div>
</script>
//主干视图
window.CaseView=Backbone.View.extend({
el:$(“#main”),
初始化:函数(){
_.bindAll(这是“呈现”);
这个。render();
},
iTemplate:$(“#tmplCase”).template(),
render:function(){
var=这个;
fadeOut('fast',function(){
$.tmpl(that.iTemplate,that.model.toJSON()).appendTo(that.el);
那.el.fadeIn('fast');
});
归还这个;
}
});
//html文件
${title}
${active}

您可以将if语句添加到模板中:

// html file

<script id="tmplCase" type="text/x-jquery-tmpl">


  <div {{if active == 1}}class="caseInActive"{{/if}}>


    <span class="title">${title}</span>
    <span class="current_status">${active}</span>
  </div>
</script>
//html文件
${title}
${active}