我的表格如下:
<div class="modal-body">
<table class="table table-sm table-inverse table-responsive table-striped">
<thead>
<tr>
<th>SL No.</th>
<th>RuleName</th>
<th>Message</th>
<th>Priority</th>
<th>Active</th>
</tr>
</thead>
<tr ng-repeat="eachData in ruleEngineData">
<td>{{$index + 1}}</td>
<td>{{eachData.ruleType.ref}}</td>
<td>{{eachData.ruleType.message}}</td>
<td>
<input id="number" type="number" value={{eachData.ruleType.priority}} min="1" max="3">
</td>
<td>
<label class="switch">
<input ng-if="eachData.active == true" type="checkbox" checked>
<input ng-if="eachData.active == false" type="checkbox">
<span class="slider round"></span>
</label>
</td>
</tr>
</table>
<footer>
<button type="button" class="close" data-dismiss="modal">Cancel</button>
<button class="submit" ng-click="modifyRuleEngine(ruleEngineData)">Save</button>
</footer>
</div>
数据正确显示:
$scope.getRuleEngine = function() {
var data = {
orgId: localStorage.getItem('organization_id')
};
var config = {
params: data
};
$http.get("/getRuleEngine", config).then(getRuleEngineCallBack, getRuleEngineErrorCallback);
}
但是当我在更改“优先级”和“活动”数据后单击“保存”时,修改后的值不会发送回:
$scope.modifyRuleEngine = function(ruleEngineData) {
var dataModified = {
orgId: localStorage.getItem('organization_id')
};
var configModified = {
params: data
};
$http.get("/modifyRuleEngine", configModified).then(modifyRuleEngineCallBack, modifyRuleEngineErrorCallback);
}
ruleEngineData
中包含较早的数据,而不包含已修改的数据。
答案 0 :(得分:0)
添加了此指令:
app.directive('stringToNumber', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(value) {
return '' + value;
});
ngModel.$formatters.push(function(value) {
return parseFloat(value);
});
}
};
});
和html到:
<td>
<input id="number" type="number" string-to-number
ng-model = "eachData.ruleType.priority"
value={{eachData.ruleType.priority}} min="1" max="3">
</td>
<td>
<label class="switch">
<input ng-if="eachData.active == true" type="checkbox" checked
ng-model = "eachData.active">
<input ng-if="eachData.active == false" type="checkbox"
ng-model = "eachData.active">
<span class="slider round"></span>
</label>
</td>