我的localStorage.getItem没有更新数据库中的数据。但只有当我重新运行第二个程序时才会发生更改,它会更新localStorage并显示修改后的数据。
$scope.projectData = $.parseJSON(localStorage.setItem('projectData'));
(function() {
console.log('Local Storage Updated')
return localStorage.getItem('projectdata');
})();
我做错了什么?
答案 0 :(得分:0)
你就是这样做的
假设您的projectData是一个Object,那么您将这样做。
//localStorage.setItem('key','value');
//localStorage.getItem('key');
//You don't need to json stringify or parse if its just a string value.
localStorage.setItem('projectData', JSON.stringify($scope.projectData));
(function() {
console.log('Local Storage Updated')
return JSON.parse(localStorage.getItem('projectdata'));
})();
假设您的projectData是一个String,那么您将这样做。
//localStorage.setItem('key','value');
//localStorage.getItem('key');
//You don't need to json stringify or parse if its just a string value.
localStorage.setItem('projectData', $scope.projectData);
(function() {
console.log('Local Storage Updated')
return localStorage.getItem('projectdata');
})();
答案 1 :(得分:0)
试试这样:
$scope.projectData = {"prodnum": "63",
"price": "139.00",
"prodname": "PEANUT BUTTER INDULGENCE MS",
"quantity": "1.00",
"tax_amount": "6.95",
"parent_id": "0"}
localStorage.setItem('projectData', JSON.stringify($scope.projectData));