R01*_*010 6 checkbox model angularjs angularjs-ng-repeat
所以我需要知道汽车的额外内容,而不是用户希望包含在他的偏好中.我正在尝试从ajax请求获取的数组创建输入复选框,并通过ng-repeat生成输入.主要目标是了解用户选择的复选框.我想我的方法是创建一个辅助数组,其中包含选定的数组,但我不知道如何为ng-repeat迭代中的每个项设置一个唯一的ng模型,这样我就可以知道所选的列表项目.我想我的角度知识还有一些东西.这就是我现在拥有的......
在控制器......
$http.get('/ajax/ajax_get_extras/'+$scope.car.version+'/false').success(function(data) {
$scope.extras = data;
});
$scope.addExtra = function(){ // ... manage the auxiliar array }
Run Code Online (Sandbox Code Playgroud)
在HTML中......
<div ng-controller="Controller">
<form novalidate class="simple-form">
<span ng-repeat="extra in extras">
<input type="checkbox" ng-model="extra.id" ng-change="addExtra()" name="extra_{{extra.id}}" >{{extra.name}} - <strong>{{extra.real_price | onlynumber | currency}}</strong>
</span>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
而且我被困了,因为extra.id不会转换为真正的extra.id并保持为字符串"extra.id"> _ <
我尝试了额外的_ {{extra.id}},extra.id,{{extra.id}},$ index作为posibles ng-model,但没有效果.
Val*_*nov 13
在AngularJS 1.1.5中,您可以在ngRepeat中使用"track by".
所以你可以:
<input type="checkbox" ng-repeat="e in extra track by $index" ng-model="extra[$index]">
Run Code Online (Sandbox Code Playgroud)
这是一个例子:http: //plnkr.co/edit/6lNo6R5EPsNGHUU6ufTE?p = preview
| 归档时间: |
|
| 查看次数: |
16529 次 |
| 最近记录: |