[英]couldn't show list of documents in the view using derbyjs
It's my first time with derbyjs, don't know if i am being stupid or is it a lack of documentation. 这是我第一次使用derbyjs,不知道我是不是很愚蠢,还是缺少文档。 i have a model called "books", and i am just trying to show list of books.
我有一个称为“书籍”的模型,而我只是想显示书籍清单。
here is my code: 这是我的代码:
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']
}
and the schema list 和模式列表
module.exports = {
schemas: {
auths: require('./model/auths'),
products: require('./model/products'),
books: require('./model/books')
}
}
the index js 索引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');
});
});
i expect to have "books" in the view, so i wrote {{each}} like this 我希望视图中有“书”,所以我这样写了{{each}}
{{ each books as #b}}
{{ #b.title }}
{{/each}}
but nothing shows up, although this works fine and render as expected 但是没有任何显示,尽管可以正常工作并按预期方式渲染
{{ _page.book.title }}
also at the web console, this works fine and shows 3 books 也可以在网络控制台上正常运行,并显示3本书
app.model.get('books')
notice: i added the books through the web console, something like this 注意:我通过网络控制台添加了书籍,就像这样
app.model.add('books', {title: 'something'})
inside the subscribe function, i have tried to 在订阅功能中,我试图
var books = model.get('books');
model.ref('_page.books', books);
but an error rise up 但错误上升
any idea what i am doing wrong ? 知道我在做什么错吗? i really like derbyjs but this is holding me back for few days
我真的很喜欢derbyjs,但这使我退缩了几天
If you would like for the page to update automatically you should use a ref
instead of a get()
however, eg 如果您希望页面自动更新,则应使用
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');
});
});
Template: 模板:
{{ each _page.books as #b}}
{{ #b.title }}
{{/each}
In addition to the official Derby docs I've found the derby-faq to be a good resource. 除了官方的Derby文档外,我还发现derby-faq是很好的资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.