Backbone.js 模型更改和模板数据更改时的trigget和event,Backbonejs

Backbone.js 模型更改和模板数据更改时的trigget和event,Backbonejs,backbone.js,Backbone.js,假设我在backbonejs模板上设置了如下条件: <% if(model.get(attribute) === true) { %> display X <% } else { %> display Y <% { %> myView = Backbone.View.extend({ el: '.main', render : function() { template = _.templa

假设我在backbonejs模板上设置了如下条件:

 <% if(model.get(attribute) === true) { %>
      display X
 <% } else { %>
     display Y
 <% { %>
 myView = Backbone.View.extend({
     el: '.main',

     render : function() {
        template = _.template($('#myTemaplte').html(), { models : this.collection.models });
        this.$el.html(template);
     }
 });



 var theCollection = new Collections.myCollection;
 theCollection.fetch({
    success: function (data) {
            myList = new myView({collection : theCollection});
    }
 });  
所以问题是。。。我是否可以在不重新加载页面或调用控制器的情况下将前端更改为“显示Y”

任何帮助都将不胜感激

提前谢谢

更新

我的观点是这样的:

 <% if(model.get(attribute) === true) { %>
      display X
 <% } else { %>
     display Y
 <% { %>
 myView = Backbone.View.extend({
     el: '.main',

     render : function() {
        template = _.template($('#myTemaplte').html(), { models : this.collection.models });
        this.$el.html(template);
     }
 });



 var theCollection = new Collections.myCollection;
 theCollection.fetch({
    success: function (data) {
            myList = new myView({collection : theCollection});
    }
 });  
json文件如下所示:

 data [
  {
   "atribute" : false
  },
  {
   "atribute" : true
  },
  {
   "atribute" : false
  },
 ]
试试这个

 myView = Backbone.View.extend({
         el: '.main',

         initalize : function(){
         this.listenTo(this.collection,'change',this.render); 
         },
         render : function() {
            template = _.template($('#myTemaplte').html(), { models : this.collection.models });
            this.$el.html(template);
         }
     });

显示您的视图/控制器。我没有访问API控制器的权限,它只返回一个json,其中我正在设置的属性设置为false,并且我的视图上除了模板呈现之外没有其他内容,这就是为什么我没有发布它,它会有什么不同吗?我在询问您的主干视图,也许我可以将逻辑添加到iTUpdate:)@aktiv coder