开发者

Backbone & jQuery Tmpl - applying style to template item

开发者 https://www.devze.com 2023-03-29 04:24 出处:网络
my backbone view looks like this below and is rendered with the jQuery tmpl library.I want to apply a style to one/all/any of the data items for which

my backbone view looks like this below and is rendered with the jQuery tmpl library. I want to apply a style to one/all/any of the data items for which active==1. Any ideas on how to do this?

   // 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() {
      开发者_如何学Go      $.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>


you can add if statements to your template:

// 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>

http://api.jquery.com/template-tag-if/

0

精彩评论

暂无评论...
验证码 换一张
取 消