AngularJS的双向绑定特性的确很好用,但是在实际使用中遇到了一些问题:我首先使用ng-repeat将数据重复展示出来(item in datas),然后在关联的modal对话框中提供修改功能(将item的对应项使用ng-model绑在modal的form上),但是由于双向绑定的原因,即便未点击保存按钮,在对话框中的修改也会实时影响到页面上的展示数据,这样有些影响体验,有没有好的解决方法呢?我也尝试在js中使用一个中间变量来保存未修改的数据,但是一旦item变化,中间变量也改变了。
相关代码
html:
{{item.name}}
{{item.age}}
modify
JS:
$http.get("/").success(function(data) {
$scope.data = data;
var interItem;
$scope.fresh = function(item) {
interItem = item;
console.log(interItem);
};
$scope.reset = function() {
console.log(interItem);
}
});
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
欢迎选择我的课程,让我们一起见证您的进步~~