項目中用的前端是ftl + angular.js
今天遇到個問題關於彈出框,若點擊關閉按鈕,數據回退到彈出框初始化狀態,用到了angular.copy()方法
項目js代碼案例:
/** * 商品庫存批次修改 */ $scope._repeatItem = {}; $scope.modifyInventory = function (repeat_item) { $scope._repeatItem = angular.copy(repeat_item); //庫存批次賦值,自定義,雙向綁定數據 $scope['repeat_item'] = repeat_item; //彈出框展示 $('.deduct_segmentation_box').modal("show"); }
/** * 點擊關閉按鈕,新增清空之前數據,編輯還原以前數據 */ $scope.colseBatchGoods = function (className) { angular.copy($scope._repeatItem, $scope.repeat_item); $("." + className).modal("hide"); };
其中重點在如下代碼:angular.copy($scope._repeatItem, $scope.repeat_item);
//重置數據的層面放在此處,此處將 $scope._repeatItem 深拷貝到 $scope.repeat_item 中,可以根據需求放入原來的模型。