[英]How to populate jquery mobile listview from pouchdb data
我正在使用jquery mobile和pouchdb開發簡單的移動應用程序。 我通過此鏈接http://pouchdb.com/getting-started.html跟隨了教程。
我試圖填充從pouchdb數據檢索的Jquery Mobile listview。 例如,名字(David),每個名字都將鏈接到一個新頁面,該頁面提供了完整的信息,例如電子郵件,年齡等。
我被這條線卡住了
函數redrawUi(mydb){
這是源代碼。 http://jsfiddle.net/Vanilla/p2u8wc5p/
提前致謝。
var db = new PouchDB('mydb'); var remoteCouch = 'http://localhost:5984/mydb'; db.info(function(err, info) { db.changes({ since: info.update_seq, live: true }).on('change', showTodos); }); db.put({ _id: new Date().toISOString(), email: 'dave@gmail.com', name: 'David', }); db.changes().on('change', function() { console.log('Ch-Ch-Changes'); }); db.replicate.to('http://127.0.0.1:5984/mydb'); db.replicate.from('http://127.0.0.1:5984/mydb'); function showdetail() { db.allDocs({ include_docs: true, descending: true }).then(function(doc) { redrawUi(doc.rows); }). catch(function(err) { console.log(err); }); } function redrawUi(mydb) { }); }
假設您返回了一個包含ID,名稱和電子郵件的對象數組。 您只需要迭代數組,創建listitem標記並將其附加到現有的listview DOM元素即可,例如:
function redrawUi(mydb) {
var itemsHTML = '';
for (var i=0; i<mydb.length; i++){
itemsHTML += '<li>' + mydb[i].name + ' - ' + mydb[i].email + '</li>';
}
$("#list").empty().append(itemsHTML).listview("refresh");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.