0
我有一個離子應用程序,其中有7個輸入字段。我正在做的是我將這些值從輸入字段保存到本地存儲中。下面是我在angularjs控制器代碼:將數據保存在離子應用程序的LocalStorage中
window.localStorage.setItem('Frames', JSON.stringify(PositionFrames));
$scope.Save = function() {
var FrameValues = {
"PositionName": $scope.data.PositionName,
"box1": 'j0' + $scope.data.box1,
"box2": 'j1' + $scope.data.box2,
"box3": 'j2' + $scope.data.box3,
"box4": 'j3' + $scope.data.box4,
"box5": 'j4' + $scope.data.box5,
"box6": 'gr' + $scope.data.box6
};
var temp = [];
tmp = JSON.parse(window.localStorage.getItem('Frames'));
temp.push(tmp);
temp.push(FrameValues);
window.localStorage.setItem('Frames', JSON.stringify(temp));
// window.localStorage['Frames'] = JSON.stringify(temp)
console.log(JSON.stringify(temp));
};
每當我打按鈕來保存的console.log數據和打印數據,我可以看到下面的結果:
[[[{"PositionName":"Home","box1":90,"box2":90,"box3":90,"box4":90,"box5":90,"box6":90}],{"PositionName":"Amrit","box1":"j058","box2":"j161","box3":"j2143","box4":"j3152","box5":"j4157","box6":"gr159"}],{"PositionName":"Amrit","box1":"j058","box2":"j161","box3":"j2143","box4":"j3152","box5":"j4157","box6":"gr159"}]
但是如果你不是在看數據順序,我不知道爲什麼它不是像這樣的格式[{},{},{}]。我無法弄清楚這些額外的[[[來自哪裏]。
我該如何解決?
由於男人愛:)