angularjs - ng-click 没有从表中返回修改过的数据
问题描述
我的表如下:
<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
有较早的数据,而不是修改过的数据。
解决方案
添加了这个指令:
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>
推荐阅读
- flutter - 如何更改日志记录级别
- r - 在R中自动查找数据框的连接列块
- excel - 如何修复变量集合对象抛出“需要对象(424)”错误?
- node.js - Winston 日志记录对象
- python - Google App Engine 在启动时自动填充 Google 数据存储中的初始数据
- laravel - 我的引导轮播不工作,我用引导 4.3 创建了轮播
- java - 如何处理 Java 中未知的 protobuf 字段?
- java - “java.sql.SQLException:ResultSet 不可更新”与 JdbcRowSet
- c++ - 如何安全地删除新分配的结构?
- php - 发送电子邮件时我无法访问对象的内容