0
我建設,我有選擇類型的多個輸入組件的以前的狀態,他們已經被要求選擇。當使用需要字段中,它從使用requiredfields的陣列中刪除,並添加到requiredFieldsRemoved陣列。如果我改變了主意,選擇了選擇的另一種選擇,我選擇不要求我必須返回已刪除對象的字段推入requiredFieldsRemoved並返回到原來使用requiredfields陣列。Angularjs - 獲得一個對象
我所做的是增加NG-更改輸入選擇返回已更改的對象,所以我現在需要的是把以前的狀態保存有關的不同而變化的選擇可以有。
//@Param publicationObject: change object from UI
$scope.itemValue = function (publicationObject) {
// get the index using lodash
var idx = lodash.findKey($scope.requiredFields, {
name: publicationObject.name
});
// here I have to check whether the object already suffered
// changes above or if it's his first change.
// if it have change previously, i will check if that status match
// to any object of the requiredFieldsRemoved array
// and push it again to the requiredFields array, if not i just do nothing.
//
//if index is found, delete the item from required fields array
if(idx !== undefined) {
$scope.requiredFields.splice(idx, 1);
//add removed item to the requiredFieldsRemoved array
requiredFieldsRemoved.push(publicationObject);
}
};
什麼我可以實現獲取這些以前的狀態?
$ scope.itemValue =函數(publicationObject){ VAR屬性oldValue = angular.copy(publicationObject) }; –
嘗試使用angular.copy編輯之前儲存的舊值 –