简体   繁体   English

Choices.js:将动态数据添加到 select 选项中

[英]Choices.js: Add dynamic data into the select option

I'm using Choices.js for multi select and for a select with a search box.我将Choices.js用于多 select 和带有搜索框的 select。 I am also using angular.js to populate the data but it doesn't seem to work.我也在使用 angular.js 来填充数据,但它似乎不起作用。 Can anybody help me with populating the options dynamically.任何人都可以帮助我动态填充选项。

The data is being retrieved using Ajax.正在使用 Ajax 检索数据。

This is what I've tried这是我尝试过的

<label for="docno" class="col-form-label">Name :</label>
<select id='docno' class="choices form-select" ng-model="docno" ng-change='getDocs()' required="true">
     <option ng-repeat="d in documents" ng-value="d.docno" selected='selected'>{{d.name}}</option>
</select>

You can use setValue in choices instance like below:您可以在选择实例中使用 setValue,如下所示:

 var choices = new Choices(document.getGetElementById("docno")); var myDynamicItems = [ { value: 'Value 1', label: 'Label 1', id: 1 }, { value: 'Value 2', label: 'Label 2', id: 2 } ]; inst.choices.setValue(myDynamicItems);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM