gpt4 book ai didi

javascript - 在运行时创建下拉菜单并随后绑定(bind)下拉列表值 - ngOptions 不起作用

转载 作者:行者123 更新时间:2023-11-28 07:21:16 25 4
gpt4 key购买 nike

我正在使用 AngularJs 在运行时生成下拉菜单。我还想与其绑定(bind)相应的选项,这些选项将根据创建的下拉列表类型生成。

<div class="form-group" ng-repeat="attrib in col1Attribs">
<label class="control-label" for="txtCode">{{attrib.displayText}}</label>
<select class="form-control"
ng-options="item.configValue for item in configOptions(attrib.configType)" />
</div>

我的 Controller 有以下方法。

$scope.configOptions = function (type){
return SmartCache.get(type); //SmartCache is my cacheFactory
}

编辑:

这是我的数据,当参数type = 'Status'

[{"$id":"1","people":[],"configId":"STAT001","configValue":"Active","startDate":"2014-01-31T00:00:00","endDate":"9999-01-01T00:00:00","description":"Active","status":1,"parentId":null,"isSelectable":true,"timestamp":"AAAAAAAAKHM=","isSystemData":true,"children":[],"parent":null,"personAttributes":[],"items1":[]},{"$id":"2","people":[],"configId":"STAT002","configValue":"Suspended","startDate":"2014-01-31T00:00:00","endDate":"9999-01-01T00:00:00","description":"Suspended","status":1,"parentId":null,"isSelectable":true,"timestamp":"AAAAAAAAKHQ=","isSystemData":true,"children":[],"parent":null,"personAttributes":[],"items1":[]},{"$id":"3","people":[],"configId":"STAT003","configValue":"Terminated","startDate":"2014-01-31T00:00:00","endDate":"9999-01-01T00:00:00","description":"Terminated","status":1,"parentId":null,"isSelectable":true,"timestamp":"AAAAAAAAKHU=","isSystemData":true,"children":[],"parent":null,"personAttributes":[],"items1":[]},{"$id":"4","people":[],"configId":"STAT004","configValue":"Deleted","startDate":"2014-01-31T00:00:00","endDate":"9999-01-01T00:00:00","description":"Deleted","status":1,"parentId":null,"isSelectable":true,"timestamp":"AAAAAAAAKHY=","isSystemData":true,"children":[],"parent":null,"personAttributes":[],"items1":[]}]

我可以使用下面的代码来完成我的任务,但不能使用 ngOptions。

<div class="form-group" ng-repeat="attrib in col1Attribs">
<label class="control-label" for="txtCode">{{attrib.displayText}}</label>
<select class="form-control">
<option ng-repeat="c in configOptions(attrib.configType)" value="{{c.configId}}">
{{c.configValue}}</option>
</div>
</div>

试试这个 jsFiddle

最佳答案

我看不到你的其余代码。以下是如何创建下拉菜单的片段:

 <select data-ng-options="e.description for e in configOptions" data-ng-model="selectedOption" />

演示:http://plnkr.co/edit/YcuqZ1gs4iDAAgfLrZPO?p=preview

关于javascript - 在运行时创建下拉菜单并随后绑定(bind)下拉列表值 - ngOptions 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30295012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com