簡體   English   中英

使用derbyjs無法在視圖中顯示文檔列表

[英]couldn't show list of documents in the view using derbyjs

這是我第一次使用derbyjs,不知道我是不是很愚蠢,還是缺少文檔。 我有一個稱為“書籍”的模型,而我只是想顯示書籍清單。

這是我的代碼:

module.exports = {
    properties: {
        title: {type: 'string', minLength: 6},
        author: {type: 'integer', minimum: 0},
        image: {type: 'string'},
        status: {type: 'integer', minimum: 0, maximum: 1}, // 1 read, 0 wants to read
        comment: {type: 'string'}
    },
    required: ['title']
}

和模式列表

module.exports = {
    schemas: {
        auths: require('./model/auths'),
        products: require('./model/products'),
        books: require('./model/books')
    }
}

索引js

app.get('/shelf', function(page, model, params, next){
    model.subscribe('books', function(){
        var book = model.at('books.669374b5-8470-4f3a-a25f-0995a5a92a7a');
        model.ref('_page.book', book);
        page.render('home');
    });
});

我希望視圖中有“書”,所以我這樣寫了{{each}}

{{ each books as #b}}
    {{ #b.title }}
{{/each}}

但是沒有任何顯示,盡管可以正常工作並按預期方式渲染

{{ _page.book.title }}

也可以在網絡控制台上正常運行,並顯示3本書

app.model.get('books')

注意:我通過網絡控制台添加了書籍,就像這樣

app.model.add('books', {title: 'something'})

在訂閱功能中,我試圖

var books = model.get('books');
model.ref('_page.books', books);

但錯誤上升

知道我在做什么錯嗎? 我真的很喜歡derbyjs,但這使我退縮了幾天

如果您希望頁面自動更新,則應使用ref而不是get() ,例如

app.get('/shelf', function(page, model, params, next) {
  var booksQuery = model.query('books', {});
  model.subscribe(booksQuery, function(err) {
    booksQuery.ref('_page.books');
    page.render('books');
  });
});

模板:

{{ each _page.books as #b}}
  {{ #b.title }}
{{/each}

除了官方的Derby文檔外,我還發現derby-faq是很好的資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM