1) Because of implementation of ShareJS at the moment there is only possible to subscribe(fetch) at minimum to the whole document. It means that you can not get from server just title
of the article.
Workarounds:
- You can make method in Express router, which would return list of
id
+title
. And you can make XMLHttpRequest request from client (as usual) to get it and put to client model. - You can split collections. First for
titles
, second fortexts
- Maybe there are more
2) In this example html will start render only after article is loaded to client:
app.get('/articles/:id', function(page, model, params, next) {
// let's load the article
model.subscribe('/articles/' + params.id, function(err) {
// article is loaded now let's start to render html
page.render('article');
});
});
In this example html will start render before article is loaded, and after article is loaded html will be filled with data (if you use {} and not {{}} in template):
app.get('/articles/:id', function(page, model, params, next) {
// let's load the article
model.subscribe('/articles/' + params.id, function(err) {
// article is loaded and html is filled with data
});
// Still no article, let's render page without data
page.render('article');
});