Faced such a problem! Adding an element to the beginning of the array. The procedure I numbered, and the code laid out here .
The array is called Returned_Json. The bottom line is simple. Add comments to localStorage.
I will be very grateful!
Once again link ( http://codepen.io/Brave_Lime/pen/PzzwXm?editors=0010 )
Here is the main piece:
function main_json(a){ if(a==0){ //6 localStorage.setItem('LocalStorage', Returned_Json); //Здесь Обновиться localStorage console.log(localStorage.LocalStorage); } else { // 3 Returned_Json = JSON.parse(localStorage.getItem('LocalStorage'));//Здесь он создается console.log(Returned_Json); return Returned_Json; } }; function post_comment() { //2 $.each(main_json().posts, function(i, post){ //7 var list='<div>'; ... list+='</div>'; $("#Main_Content_Comment").append(list); }); }; function post() { //4 main_json().posts.unshift( //**//Здесь должен изменяться - Основная проблема! Не добавляется в массив. { "time": '10', }); var a=0; console.log(main_json().posts); console.log(Returned_Json); console.log(localStorage.LocalStorage); main_json(a); //5 post_comment(); }; $(document).ready(function() { post_comment(); }); Problem: in main_json().posts (in fact, this is an array of Returned_Json ) the specified element is not added. What stupid further performance ...
main_jsonquestion is too wide, as well as withoutpost_comment. In addition, in the last question we decided that we just need to write the modified array back to localStorage - Grundy