我在ChaplinJS中有一个集合,它具有以下初始化代码:
Chaplin = require 'chaplin'
Collection = require 'models/base/collection'
Domain = require 'models/domain'
mediator = require 'mediator'
module.exports = class Domains extends Collection
model: Domain
# Initialize the SyncMachine
_(@prototype).extend Chaplin.SyncMachine
initialize: ->
super
@.totalHits = 0如何在其视图的模板中引用totalHits?我使用的是handlebars模板,编写{{totalHits}}不会返回任何内容。
顺便说一句,我不应该用以下命令重写上面的代码:
module.exports = class Domains extends Collection
model: Domain
totalHits: 0发布于 2013-03-31 07:16:12
找到解决方案:
在我的CollectionView中,我可以重写getTemplateData并向它传递任何我想要的东西,包括完整的集合对象:
getTemplateData: ->
templateData = super
templateData.collection = @.collection
templateData然后在handlebars模板中,我可以执行{{collection.totalHits}}
https://stackoverflow.com/questions/15722558
复制相似问题