Javascript 在AngularJS中通过模态编辑对象-使用临时对象?
场景:用户单击项目。下面的代码运行并打开一个模式,其中包含一个填充了项目名称的文本框Javascript 在AngularJS中通过模态编辑对象-使用临时对象?,javascript,angularjs,Javascript,Angularjs,场景:用户单击项目。下面的代码运行并打开一个模式,其中包含一个填充了项目名称的文本框 $scope.edit = function (item) { $scope.editingItem = { Name: item.Name }; }; 模式中的我的HTML: <input type="text" ng-model="editingItem.Name"/> 导致: $scope.update = function (item) { // What do I pu
$scope.edit = function (item) {
$scope.editingItem = { Name: item.Name };
};
模式中的我的HTML:
<input type="text" ng-model="editingItem.Name"/>
导致:
$scope.update = function (item) {
// What do I put in here to update the original item object that was passed
// into the edit function at the top of this question?!
};
但我的问题是,在update
方法中放入什么?我想更新原始的项目
(保存在项目数组中)。我会这样做:
$scope.edit = function (item) {
$scope.editingItem = { Name: item.Name };
$scope.originalItem = item;//store the instance of the item to edit
};
$scope.update = function (item) {
$scope.originalItem.Name = item.Name;//copy the attributes you need to update
//clear temp items to remove any bindings from the input
$scope.originalItem = undefined;
$scope.editingItem = undefined;
};
令人惊讶的是,这正是我完成解决方案的方式!谢谢你的确认。。。
$scope.edit = function (item) {
$scope.editingItem = { Name: item.Name };
$scope.originalItem = item;//store the instance of the item to edit
};
$scope.update = function (item) {
$scope.originalItem.Name = item.Name;//copy the attributes you need to update
//clear temp items to remove any bindings from the input
$scope.originalItem = undefined;
$scope.editingItem = undefined;
};