【发布时间】:2016-04-07 09:56:09
【问题描述】:
我有一张列出规则列表的表格。单击复选框时,我需要它们采用此“真实”值并发布到 API 端点。这已经设置好了,但我得到的是“关联规则”是未定义的。
我已经尝试在我的控制器中设置$scope.associated_rule.selected = true;,但这仍然没有定义变量并且在控制台中抛出了同样的错误。
这是我的 HTML 表单:
<form name="rules_form" method="post" ng-submit="attach()">
<table class="table table-striped table-hover" ng-model="associated_rules">
<thead>
<th>Rule Types:</th>
<th>Description:</th>
<th>Start Time:</th>
<th>End Time:</th>
<th>Apply Rule to Vehicle:</th>
</thead>
<tr ng-repeat="associated_rule in associated_rules">
<td>@{{ associated_rule.resource_ids.accounts }}</td>
<td>@{{ associated_rule.description }}</td>
<td>@{{ associated_rule.start_time }}</td>
<td>@{{ associated_rule.end_time }}</td>
<td><input type="checkbox" ng-model="associated_rule.selected" aria-label="rule"></td>
</tr>
</table>
<button class="btn btn-primary" ng-click="attach()">Attach</button>
</form>
我的控制器事件:
$scope.attach = function () {
$scope.associated_rule.selected = true;
var i;
for (i = 0; i < $scope.associated_rule.selected.length; i++) {
//need to create a loop where the true value is picked up and then I can send the data using a POST method. But I'm stuck on this.
}
console.log(the result of the event);
};
现在,我只想将结果保存到 console.log,因此我可以看到事件正在创建循环并显示结果。在那之后,我应该没事。
任何帮助将不胜感激。
【问题讨论】:
标签: javascript angularjs loops