0
我已經創建了一個函數readAll(),它將數據提取到todos div中,但它沒有顯示點擊函數的數據,但它不工作數據正在成功添加索引數據庫但它沒有顯示。現在,我首先我已經清空表格後,我只是將數據附加到JavaScript的HTML。如何從indexeddb中檢索數據並顯示在div中
function readAll() {
var objectStore = db.transaction("todostore").objectStore("todostore");
$("#todos").empty();
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
$("#todos").append("<tr><td>" + cursor.key + "</td><td>" + cursor.value.todo + "</td><td><button onclick=\"update('" + cursor.key + "','" + cursor.value.todo + "')\">Update</button></td><td><button onclick=\"removetodo('" + cursor.key + "','" + cursor.value.todo + "')\">Delete</button></td></tr>");
cursor.continue();
}
};
};
我現在呼籲點擊我打電話的readAll功能
$(".clickme").click(function(){
readAll();
});
我已經創建div我有現在的我使用一個表頭裏面的id視圖的DIV功能剛剛從附加的JavaScript代碼,並填充到HTML
<div id="view">
<thead>
<tr class="ui-bar-d">
<th data-priority="2">Timestamp</th>
<th data-priority="1">To Do</th>
<th data-priority="3">Update</th>
<th data-priority="4">Delete</th>
</tr>
</thead>
<tbody id="todos">
</tbody>
</table>
</div>
<label for="todo">To Do:</label>
<input id="todo" type="text">
<input id="toprice" type="text">
<button class="clickme">clickme</button>
<button class="ui-shadow ui-btn ui-corner-all" onclick="add()">Add</button>
你的HTML格式不正確。 – sweaver2112
你能告訴我哪裏錯了嗎 –
失蹤
回答
由於IDB是async.You需要調用你在....
功能https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/oncomplete
來源
2016-12-09 19:28:10
相關問題