2

我使用 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++;

值得到更新,但它不会更改选定的值文本,而如果我点击下拉菜单,我会在下拉菜单中获得更改的值 在此处输入图像描述

有人可以指导我如何解决这个问题,任何帮助将不胜感激

4

1 回答 1

3

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

例如

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>

那么您应该能够成功选择该值。

于 2014-04-16T15:55:32.407 回答