1
は私が持っているチェックボックスに配列をバインドし、次のJSとHTML:このような何かを見AngularJsは
$scope.loadInstallation = function (installationid) {
$scope.currentInstallation = {};
$scope.currentInstallation = $scope.installationList[installationid];;
$scope.currentInstallationID = installationid;
};
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="installationmoduleIdList1">Module 1:</label>
<div class="form-control">
<label><input type="checkbox" id="installationmoduleIdList1" ng-model="currentInstallation.moduleIdList" /></label>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="installationmoduleIdList2">Module 2:</label>
<div class="form-control">
<label><input type="checkbox" id="installationmoduleIdList2" ng-model="currentInstallation.moduleIdList" /></label>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="installationmoduleIdList3">Module 3:</label>
<div class="form-control">
<label><input type="checkbox" id="installationmoduleIdList3" ng-model="currentInstallation.moduleIdList" /></label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="installationmoduleIdList4">Module 4:</label>
<div class="form-control">
<label><input type="checkbox" id="installationmoduleIdList4" ng-model="currentInstallation.moduleIdList" /></label>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="installationmoduleIdList5">Module 5:</label>
<div class="form-control">
<label><input type="checkbox" id="installationmoduleIdList5" ng-model="currentInstallation.moduleIdList" /></label>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="installationmoduleIdList6">Module 6:</label>
<div class="form-control">
<label><input type="checkbox" id="installationmoduleIdList6" ng-model="currentInstallation.moduleIdList" /></label>
</div>
</div>
</div>
</div>
とJSON、:
currentInstallation =
{
"id":"1",
"moduleIdList": [ "1", "2" ]
}
を」 "moduleIdList" HTMLの "moduleIdList"の "1"が "true"の場合、問題は "moduleIdList"をチェックボックスにバインドする方法で、 "1" in "m oduleIdList "チェックボックスがオンになっていてチェックを外すと、" 1 "が配列から削除されます
私の問題を理解できたら幸いです。
挨拶、 サイモン
は、それはそうし私にはデフォルトの 'ng-model'を使うだけでは不可能です。おそらく、それを行う方法はあなたの 'moduleIdList'配列を変更することです – xAqweRx
ええ、知っています、それはng-modelとは関係ないので、残念ながら私はmoduelIdListを変更することができないので、 array – TZimon
あなたのモデルの 'moduleIdList'のバージョンを変換して修正する' Controller'関数を実装するのが簡単です。それで全部です。普通の 'for-loop' – xAqweRx