【发布时间】:2013-12-27 19:51:10
【问题描述】:
我在 http://jsfiddle.net/skwidgets/gnvVY/13/ 设置了一个 jsfiddle
基本上有一个 div,其中包含一些表单元素,包括两个下拉菜单、一个单选按钮组和一个用于删除该行的链接。
<div ng-app="myapp">
<div id="w" ng-controller="survey">
<div class="qs">
<div class="">1</div>
<div class="">
<select data-role="none" name="w1.selected_location" data-ng-model="w.w1.selected_location" ng-options="location.value as location.label for location in locations">
<option value="">Choose a Location</option>
</select>
</div>
<div class="">
<select data-role="none" name="selected_stage" data-ng-model="w.w1.selected_stage" ng-options="stage.value as stage.label for stage in stages">
<option value="">Choose a Stage</option>
</select>
</div>
<div class="">
<input data-role="none" type="radio" name="wI4" value="true" data-ng-model="w.w1.wIn24">
</div>
<div class="">
<input data-role="none" type="radio" name="wI4" value="false" data-ng-model="w.w1.wIn24">
</div> <a href="#">Remove</a>
</div>
<div>
<button data-role="none">Add Row/button>{{w | json}}</div>
</div>
</div>
<script>
var locations = [{
label: 'Head',
value: 9,
}, {
label: 'Shoulders',
value: 5,
}
// ... more would go here
];
var stages = [{
label: 'I',
value: 0
}, {
label: 'II',
value: 1
}];
</script>
它们被包裹在一个带有“qs”类的 div 中。所有选择都填充到一个名为“w1”的模型中。如果用户想要添加另一个,则有一个按钮可以添加这些表单元素的另一行以及父容器到 dom,但它必须具有不同的模型名称,相似到 (w1) 的第一个,但模型名称中的数字递增(w2、w3 等),行号也是如此。
我试图制定一个指令来处理这种行为,但没有任何运气。
任何想法都会受到赞赏。
【问题讨论】:
标签: javascript angularjs angularjs-directive