Can anyone please explain how to create a table and insert data in to the table in local storage for Chrome extensions? I need to retrieve the values from the table and do some validation.
问问题
1402 次
1 回答
0
您可以 JSON.stringify() 您的表,然后在需要时再次使用 JSON.parse() 。
例子:
var table = [ { name : "Tom" , zip : 8210 } , { name : "Bob" , zip : 8201 } ];
localStorage.table = JSON.stringify( table );
console.log( localStorage.table ); //For the curious folks ( assuming Chrome here )
var retrievedTable = JSON.parse( localStorage.table );
console.log( retrievedTable );
当然你需要一些断言,你不想盲目地解析 localStorage 数据。
T。
于 2012-05-22T13:11:59.967 回答