【问题标题】:ui select 2 selected value doesnt change - angularjsui select2 选择的值不会改变 - angularjs
【发布时间】:2014-04-04 15:35:04
【问题描述】:

我使用 ui.select2 进行下拉菜单

场景 我有一个返回下拉值的 ajax 调用

document.dropDownDocStatuses = [
            { key: 0, value: 'All active (' + response.totalDocuments + ')' },
            { key: 1, value: 'Draft (' + response.draft + ')' }            
        ];

在html中我有

<select ui-select2 class="form-control font-12px input-style3 " 
ng-model="document.dropDownDocStatus"        
ng-change="document.filterDocuments()">
<option ng-repeat="documents in document.dropDownDocStatuses"  value="{{documents.key}}">({{documents.value}})</option>  </select>

用户已选择值

问题 现在,当我使用

更新下拉列表的任何值时
  _document.dropDownDocStatuses[_document.dropDownDocStatus].value++;
                _document.dropDownDocStatuses[1].value++;

value 得到更新,但它不会更改选定的值文本,而如果我单击下拉菜单,我会在下拉菜单中获得更改的值

谁能指导我如何解决这个问题,任何帮助将不胜感激

【问题讨论】:

    标签: javascript angularjs ui-select2


    【解决方案1】:

    我刚刚遇到了和你一样的问题,根本原因是ng-model字段,你不应该使用“options”字段来存储ng-model,尝试为ng-创建另一个字段模型,您将能够选择值。

    例如

    document.dropDownDocStatuses = [
                { key: 0, value: 'All active (' + response.totalDocuments + ')' },
                { key: 1, value: 'Draft (' + response.draft + ')' }            
            ];
    document.selectedDocStatus = [];
    

    在 HTML 中:

    <select ui-select2 class="form-control font-12px input-style3 " 
    ng-model="document.selectedDocStatus"        
    ng-change="document.filterDocuments()">
    <option ng-repeat="documents in document.dropDownDocStatuses"  value="{{documents.key}}">({{documents.value}})</option>  </select>
    

    那么您应该可以成功选择值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多