我正在使用angular-ui的select2指令。在功能方面它工作正常(在一些头发拉动后),但我只是意识到,我所做的工作是防止select2显示选定的值。使用select2无法显示选定的值
<select
ui-select2
id="entityDropDown"
ng-model="selectedUser"
ng-value="users[selectedUser].name"
ng-change="getUserInfo(users[selectedUser])">
<option></option>
<option ng-repeat="user in users" ng-value="{{$index}}" value="{{user.name}}">{{user.name}}</option>
</select>
起初我使用的是ngOptions,但它与Select2不兼容,所以必须使用ngRepeat。我的ngRepeat需要将选定的用户对象发送到更改时的函数。要做到这一点,我不得不使用ng值或值来绑定选定的用户$索引到选择元素ng模式selectedUser
从那里我可以根据索引在用户中查找对象。 BUUUT,现在我已经给出了我的选项$ index,返回到select2的值没有意义,我猜,它只是给我我的占位符。
.run(['uiSelect2Config', function(uiSelect2Config) {
uiSelect2Config.placeholder = "Click here";
uiSelect2Config.dropdownAutoWidth = true;
}]);
我试图给select元素它自己的NG-值来样做什么ngChange在做,并期待选定的用户名称....但没有工作了啊。
Ah k我想我明白你在做什么。你基本上在控制器内部移动所有的计算,所以它不会影响select2的值吗?说得通。 – Batman
我试过了,但由于一些血腥的原因,它仍然不会显示与select2:http://jsfiddle.net/Ay7jA/我做错了吗? – Batman
jQuery只在第一次运行,当我改变用户时它不起作用。 – Batman