【问题标题】:Choices.js: Add dynamic data into the select optionChoices.js:将动态数据添加到选择选项中
【发布时间】:2022-01-07 18:37:03
【问题描述】:

我使用Choices.js 进行多选和带有搜索框的选择。我也在使用 angular.js 来填充数据,但它似乎不起作用。谁能帮我动态填充选项。

正在使用 Ajax 检索数据。

这是我尝试过的

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

【问题讨论】:

    标签: javascript angularjs ajax


    【解决方案1】:

    您可以在选择实例中使用 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);

    【讨论】:

    • 不幸的是,我的页面要复杂得多,无法使用choices.setValue(),我最终使用Select2,它工作正常!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    相关资源
    最近更新 更多