Select2 acts very different with Uncaught query function not defined for Select2 <select2-id>

匿名 (未验证) 提交于 2019-12-03 00:51:01

问题:

I load values for select2 like the following way.

Declare the Type

var  AdjustmentType = Backbone.Model.extend({             url : Hexgen.getContextPath("/referencedata/adjustmenttype")     }); 

create instance for the Type

var adjustmentTypes = new AdjustmentType(); 

load the values to select2 box

adjustmentTypes.fetch({                     success : function() {                         for(var count in adjustmentTypes.attributes) {                             $("#adjustment-type").append("<option>" + adjustmentTypes.attributes[count] + "</option>");                         }                     }                 });                   $("#adjustment-type").select2({                      placeholder: "Select Adjustment Type",                      allowClear: true                  }); 

My HTML Code

<div class="span4">         <div>ADJUSTMENT TYPE</div>         <select id="adjustment-type" tabindex="5" style="width:200px;">             <option value=""></option>         </select>     </div> 

when i load this for the first it is not giving any exception but if i Refresh or navigate to different URL i get the following exception:

Uncaught query function not defined for Select2 adjustment-type 

回答1:

"Query" refers to the list by which to check your search terms against. You need to make sure that your data property is a proper array of objects (ie. your options elements).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!