Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过ui选择值设置ng模型值_Javascript_Angularjs_Angularjs Directive_Angular Ui_Angular Ui Bootstrap - Fatal编程技术网

Javascript 如何通过ui选择值设置ng模型值

Javascript 如何通过ui选择值设置ng模型值,javascript,angularjs,angularjs-directive,angular-ui,angular-ui-bootstrap,Javascript,Angularjs,Angularjs Directive,Angular Ui,Angular Ui Bootstrap,我目前正在项目中使用angular ui/ui select。我能够将ui select的值绑定到一个对象而不会出现问题,但是它绑定的是正在迭代的整个项。我只想基于项进行绑定。codeId这将允许我在加载页面时保留正确的数据并在下拉列表中显示正确的值 如何设置ui选择以执行此操作 <ui-select ng-model="myObject.stateCode" id="stateCode"> <ui-select-match placeholder="Select a

我目前正在项目中使用angular ui/ui select。我能够将ui select的值绑定到一个对象而不会出现问题,但是它绑定的是正在迭代的整个
项。我只想基于
项进行绑定。codeId
这将允许我在加载页面时保留正确的数据并在下拉列表中显示正确的值

如何设置ui选择以执行此操作

<ui-select ng-model="myObject.stateCode" id="stateCode">
    <ui-select-match placeholder="Select a state...">{{$select.selected.codeDescription}}</ui-select-match>
    <ui-select-choices repeat="item in constants.states | filter: $select.search" value="{{$select.selected.codeId}}">
        <div ng-bind-html="item.codeDescription | highlight: $select.search"></div>
        <small ng-bind-html="item.codeId | highlight: $select.search"></small>
    </ui-select-choices>
</ui-select>

{{$select.selected.codescription}

我相信您要做的是使用
repeat=
子句并去掉value属性。例如:

我是从中复制的:


{{$select.selected.codescription}

您的代码很好,但在使用子数组(constants.states)时,出现了一个导致此问题的错误

我刚把这个问题解决了,特别是

新版本发布。
如果您正在使用bower,只需运行
BowerUpdate

在将值绑定到stateCode之前,该操作一直有效。我认为这是因为对象和值之间的绑定?该值确实在下拉列表中选择了正确的选项,而且当我在本地(而不是在plunker中)使用它时,我会得到一个解析器错误。你需要详细说明你到底想要什么。另外-re:parser error,可能是本地托管的问题。您是在本地主机web服务器上运行它,还是只是用浏览器打开文件?这在今天的版本中已修复。“ui选择选项”中的“重复”似乎绑定了选择值。但实际上,我不知道应该在哪里找到选择值doc@Marks .
ui select
几乎没有文档,您必须从示例中推断出来。下面urban_浣熊建议的解决方案有效,而公认的答案无效,可能是由于ui select code中的更新。。。
<ui-select ng-model="myObject.stateCode" id="stateCode">
    <ui-select-match placeholder="Select a state...">{{$select.selected.codeDescription}}</ui-select-match>
    <ui-select-choices repeat="item.codeId as item in constants.states | filter: $select.search">
        <div ng-bind-html="item.codeDescription | highlight: $select.search"></div>
        <small ng-bind-html="item.codeId | highlight: $select.search"></small>
    </ui-select-choices>
</ui-select>