次のような単純なモデルを作成できます。
define(["models/base/model"], function(Model) {
"use strict";
var IssueModel = Model.extend({
defaults:{
lastName: "Bob",
firstName: "Doe"
}
});
return IssueModel;
});
そして、コントローラーからこれを行うことができます:
this.model = new IssueModel();
そして、ビューを作成するときに、次のようにモデルを渡すことができます。
this.view = new IssueView({model: this.model});
最後に、私のテンプレートでは、これを行うことでモデルのプロパティを正常に取得できます。
Hi {{firstName}} {{lastName}}
しかし、 を使用してコレクションを定義し、IssueModel
そのコレクションを (前に示したようなモデルではなく) ビューに渡そうとすると、Handlebars テンプレートでモデルを参照する方法がわかりません。
var self = this;
this.collection = new IssueCollection();
this.collection.fetch({
success: function(collection) {
self.view = new IssueView({collection: collection});
console.log(self.collection);
},
error: function(collection, error) {
// The collection could not be retrieved.
}
});
fetch
Parse.com バックエンドから 5 つのモデルを適切に取得できることはわかっています。これは、コンソールに表示されるものだからです。
私の質問はこれです。Chaplin.js が を使用していることは知っていますgetTemplateData
が、モデルを渡すときに、ビューでプロパティを参照するために特別なことをする必要はありません。Handlebars テンプレートのビューに渡したコレクションをどのように参照、具体的には繰り返しますか?
{{#each [Model in the collection I passed to the view]}}
{{title}}
{{/each}}