如何在基于更改选择后重建选择内置下拉列表

问题描述:

从服务器中获取集合后,我正在使用backbone和selectize构建下拉列表。收集更新时,原始选择也会更新。如何在基于更改选择后重建选择内置下拉列表

但selectize未更新。这里是我的collectionReset应正确

collectionReset: function() { 
      this.select = this.$el.find('#event-type-list').selectize({ 
       plugins: ['remove_button'], 
       delimiter: ',', 
       persist: false, 
       create: false, 
       score: function (search) { 
        return function (item) { 
         return 1/item.text.toLowerCase().indexOf(search.toLowerCase()); 
        }; 
       } 
      })[0].selectize; 

到底想通了周围的工作,结束了手工打造selectize下拉列表的第一次,然后将其清除,并在以后每变动增加新的项目处理它

collectionReset: function() { 
      if(this.select == null) { 
       this.select = this.$el.find('#event-type-list').selectize({ 
        plugins: ['remove_button'], 
        delimiter: ',', 
        persist: false, 
        create: false, 
        score: function (search) { 
         return function (item) { 
          return 1/item.text.toLowerCase().indexOf(search.toLowerCase()); 
         }; 
        } 
       })[0].selectize; 
      } else { 
       this.select.clearOptions(); 
       for (var i = 0; i < this.collection.models.length; i++) { 
        var eventType = this.collection.models[i]; 
        this.select.addOption({value:eventType.get('eventTypeId'),text:eventType.get('name')}); 
       } 
      } 
     }