简体   繁体   English

如何从pouchdb数据填充jquery移动listview

[英]How to populate jquery mobile listview from pouchdb data

I'm developing simple mobile app using jquery mobile and pouchdb. 我正在使用jquery mobile和pouchdb开发简单的移动应用程序。 I followed the tutorial through this link http://pouchdb.com/getting-started.html . 我通过此链接http://pouchdb.com/getting-started.html跟随了教程。

I'm trying to populate a Jquery Mobile listview retrieve from pouchdb data. 我试图填充从pouchdb数据检索的Jquery Mobile listview。 For example name (David), each of this name will link to a new page that provided full information such as its email, age and etc. 例如,名字(David),每个名字都将链接到一个新页面,该页面提供了完整的信息,例如电子邮件,年龄等。

I got stuck at this line 我被这条线卡住了

function redrawUi(mydb) { 函数redrawUi(mydb){

Here is a source code. 这是源代码。 http://jsfiddle.net/Vanilla/p2u8wc5p/ http://jsfiddle.net/Vanilla/p2u8wc5p/

Thanks in advance. 提前致谢。

 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) { }); } 

Assuming you are returned an array of objects with id, name and email. 假设您返回了一个包含ID,名称和电子邮件的对象数组。 You would just iterate the array, create listitem markup and append it to the existing listview DOM element, eg: 您只需要迭代数组,创建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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM