我尝试了在[adding objects to array in localStorage上发布的解决方案,但它似乎对我不起作用.Mine有一个小改动,我从python flask应用程序获取值列表:
var myValue = {{ List|safe }};
onload=function appendRow() {
var names = [];
names = myValue;
var existingEntries = JSON.parse(localStorage.getItem("allEntries")) || [];
localStorage.setItem("oltbl", JSON.stringify(names));
existingEntries.push(oltbl);
localStorage.setItem("allEntries", JSON.stringify(existingEntries))
var storedNames = JSON.parse(localStorage.getItem("allEntries"));
var tbl = document.getElementById('mixed'),
row = tbl.insertRow(tbl.rows.length),
i;
for (i = 0; i < tbl.rows[0].cells.length; i++) {
createCell(row.insertCell(i), storedNames[i], 'row');
}
}
function createCell(cell, text, style) {
var div = document.createElement('div'),
txt = document.createTextNode(text);
div.appendChild(txt);
cell.appendChild(div);
}
</script>
<body>
<table id="mixed">
<tr>
<th>Title</th>
<th>Text</th>
<th>STATUS</th>
</tr>
任何指针?
答案 0 :(得分:0)
你总是设置allEntries
自己的结果,但既然你从未设置过它,那就是空白
你应该重新思考你想要实现的目标。
也
existingEntries.push(oltbl); /*oltbl IS NOT ASSIGNED*/
并导致js错误