- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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" />
关于javascript - 在运行时创建下拉菜单并随后绑定(bind)下拉列表值 - ngOptions 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30295012/
我在从 1.2.14 迁移到 1.4.8 时遇到了这个问题。这在 1.2.14 中工作正常,但我在 1.4.8 中得到无限的 $digest() 循环。这是一个Fiddle证明问题。 Fiddle 比
我正在尝试渲染选择框,但它没有按预期工作 - 选项值不正确。我查了manual ,根据它,数组(在我的例子中是对象数组)的语法是 select as label for value in array
我有这个代码: //sample of data. var combobox = new[] { new { Key = 1, Value = "a[del]", is
我一直在尝试使用 ng-options在一个选择中显示一个字体数组,该数组按数组中项目的值按字母顺序排序。 HTML Choose a font JS $scope.webfonts =
我有以下穿梭箱指令: 我的模板如下所示: template: '' + '' + '' + '' + '' + ''
我的一个选择元素中有 ngOptions 连接到我在 Controller 中创建的数组,但它只是不显示任何值。我一定是做了什么蠢事。 我确信 Angular 正在工作,并且 Controller 必
我正在使用 AngularJS,并且生成了一个具有 size 属性的对象,该属性包含一个对象数组。 var product = [ // .. sizes: [ {choice: 'o
我有一个使用经销商对象数组的选择。我可以显示经销商名称作为选项,但我还想显示距离。例如“经销商名称 - 12 英里”。 我的选择: 最佳答案 在 doc : select as label for
我正在创建一个指令,用自定义的 select 标签替换普通的 select 标签: angular.module('myModule').directive('mySelect', function(
我正在尝试创建一个下拉菜单,但是当它加载时,我得到一个空的下拉选择框。 我正在使用以下 html: 有了这些数据: [ { "year
我遇到了一个奇怪的问题,我似乎无法用我的 View 进行故障排除。我正在使用生成我网站 TreeView 的指令。当我选择一个站点时,我有两个选择框,其中填充了一个站点中的组和该站点中的列表。当选项填
老实说,我不知道我在 Angular 中做什么,所以这可能是糟糕的编码实践。无论如何,我正在尝试将一些数据加载到 中异步元素。 这是模板 HTML: Advertisers:
我有一个网络服务器 (node.js),它提供一个 JSON 文件,其中包含以下格式的语言列表:{ "en": "English", "fr": "French"}(等等)。还有一个单独的 JSON,
我有这样的结构: model = [ { name: 'name1', items: [ { name: 'subobj1' }, { name
我有一个 select 标签,我使用 AngularJS 将其绑定(bind)到广播电台对象数组。我的对象具有以下属性: { id: 'WXYZ', name: 'Radio Stat
我正在使用 AngularJS 版本 1.4.7 并且有一个包含对象数组的简单 AngularJS Controller 。我想通过 ngOptions 将这些对象显示为选项。 问题是每个对象都是重复
只是好奇我们是否可以在 ng-options 中执行文本连接。 为了获得一个下拉列表,其中包含以下值: May 2015 这可能吗?那么ng-options怎么写呢? 最佳答案 是的,这是可能的。
我正在尝试使用“track by”表达式来跟踪对象数组中按 id 进行的选择。但是,我似乎无法让它像我认为的那样工作。 //ids from server $scope.serverDTO = ['1
所以我尝试在 angularJS 中创建一个下拉选择菜单。我可以使用 ng-repeat 列出内容: {{food.name}} 它为我显示了食物列表。我想把它变成一个选择。然而,无论我尝试什
我有一个名称-值集合,用于填充选择元素。我有一个模型,我想将其链接到所选值的 id。当选择元素更改时它可以工作,但是我在将初始模型值填充到页面加载时的选择元素时遇到问题。这是plunker . 下面是
我是一名优秀的程序员,十分优秀!