我的HTML:
<ol ng-model="gcwr.checked" ng-repeat="gcwr in gcwrs" id="gcwr">
<label class="checkbox" for="{{gcwr.Id}}">
{{gcwr.Description}}
<input ng-model="gcwr.checked" type="checkbox" /></label>
</ol>
我的容器控制器:
// initialize section
$scope.gcwrs = API.GetGCWRs();
// in the save/submit function
var newContainer = $scope.newContainer;
var myGCWRS;
var tmp = angular.forEach($scope.gcwrs, function (gcwr) {
myGCWRS += gcwr.checked ? gcwr : null;
});
newContainer.GCWRs = [
angular.copy(myGCWRS)
];
问题:
GCWR 填充在表单中,但我在提交/保存函数广告中收集检查的 gcwrs 时做错了,将集合添加到 newContainer。
有任何想法吗?
-- 在 Angular 的世界里永远不会有无聊的一天 :(
解决了:
好痛啊!!!TGIF 因为现在我有一个理由。
这是解决方案:(对不起,我从原始帖子中更改了一些名称)
var selectedGCWRs = [];
var tmp = angular.forEach($scope.gcwrs, function (gcwr) {
if (gcwr.checked) {
selectedGCWRs.push(gcwr);
}
});
newContainer.GCWRs = selectedGCWRs;
.... then go on and save the newContainer.
[注意:如果我使用了 angular.copy,Angular 在 ng-repeat 中创建的 $$hashkeys 就不会被剥离;因此,服务器将拒绝此集合,因为它有一个额外的属性,即 $$hashkey,它与服务器上的模型类不匹配。通过简单地将集合传递给容器,$$hashkeys 被剥离并且服务器很高兴。]