gpt4 book ai didi

javascript - checklist-model 和 checklist-value 未更新模型或未按预期运行

转载 作者:行者123 更新时间:2023-11-28 13:11:42 26 4
gpt4 key购买 nike

下面是HTML内容

<label ng-repeat="(index, item) in field.optionValue">
<input type="checkbox"
checklist-model="formControlsValues[dbColumnName]"
checklist-value="item">{{field.optionName[index]}}
</label>

field.optionValuefield.optionName 是一个数组

field = { optionValue : ["1","2","3"], optionName : ["xxx", "yyy", "zzz"] }

checklist-model,formControlsValues[dbColumnName]是一个动态对象模型,预计在勾选/选中复选框时填充值。
在渲染过程中,formControlsValues[dbColumnName] 将是 Controller 中的 $scope.formControlsValues.Village$scope.formControlsValues.State ,并预计以下面提到的格式填充$scope.formControlsValues.Village = ["2","1"]

最佳答案

这是工作代码。我想指出的是,您必须将数字作为数字而不是字符串(带双引号)获取,因为您可能会在将来出现问题。

// Code goes here

var app = angular.module('checkList', ["checklist-model"]);

app.controller('checkListCtrl', function ($scope) {
$scope.formControlsValues = {};
$scope.field = {
optionValue : ["1","2","3"],
optionName : ["xxx", "yyy", "zzz"],
dbColumnName : "State"
};

$scope.dbColumns = ['State', 'Village'];
$scope.formControlsValues = {
Village : [],
State : []
}
});
<!DOCTYPE html>
<html ng-app="checkList">

<head>
<script data-require="angular.js@1.6.0" data-semver="1.6.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script>
<script data-require="checklist-model.js@*" data-semver="0.0.1" src="http://vitalets.github.io/checklist-model/checklist-model.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body ng-controller="checkListCtrl">
<h4>Checklist model</h4>
<div>
<label ng-repeat="(index, item) in field.optionValue">
<input type="checkbox"
checklist-model="formControlsValues[field.dbColumnName]"
checklist-value="item">{{field.optionName[index]}}
</label>
</div>
<br />
<div>
<select ng-model="field.dbColumnName" ng-options="d for d in dbColumns"></select>
</div>
<div>
<label>Selected Villages: {{formControlsValues.Village}}</label>
</div>
<div>
<label>Selected States: {{formControlsValues.State}}</label>
</div>
</body>

</html>

关于javascript - checklist-model 和 checklist-value 未更新模型或未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41893309/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com