我如何加载数据并使用 CouchBase Lite 显示它

How can i load data and display it using CouchBase Lite

我正在了解 android 应用程序的 CouchBase Lite,目前我只知道如何创建管理器、数据库、文档和 view.However 我想从中加载数据文档并将其显示在应用程序中,但在尝试几次并遵循一些 tutorials.Is 之后失败了,我可以通过某种方式加载此数据并对其进行操作? 我现在使用的代码如下:

        // create a manager
        Manager manager;
        try {
            manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS);
        } catch (IOException e) {
            getFilesDir();
            return;
        }
        // create a name for the database and make sure the name is legal
        String app4 = "list";
        if (!Manager.isValidDatabaseName(app4)) {
            return;
        }
// create a new database

        Database database;
        try {
            database = manager.getDatabase(app4);
            Log.d (TAG, "Database created");


        } catch (CouchbaseLiteException e) {
            Log.e(TAG, "Cannot get database");
            return;
        }

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("title", " Au bonheur des dames");
        properties.put("author", "Emile ZOla");

//        Document document = database.createDocument();
//        Document retrievedDocument = database.getDocument(documentID);
        Document document = database.createDocument();

        try {
            document.putProperties(properties);
        } catch (CouchbaseLiteException e) {
            Log.e(TAG, "Cannot save document", e);
        }

        Query query = database.createAllDocumentsQuery();

        try {
            QueryEnumerator queryEnumerator = query.run();
            List<QueryRow> results = new ArrayList<QueryRow>();

            for (int i=0; i< queryEnumerator.getCount(); i++) {
                results.add(queryEnumerator.getRow(i));
            }

如果有人能帮忙,我会很高兴 thankful.As 我说过我对 Couchbase 很陌生,因此可能会犯很多错误...

深入研究 map/reduce 技术来创建“View,' which is an index of documents in the database and from there 'Query”以查找视图提供的索引结果。

浏览 Couchbase Mobile mini-hack tutorial 并特别关注步骤 3-5 和 8 将有助于进一步了解如何加载和显示数据。