【发布时间】:2014-12-01 08:55:28
【问题描述】:
每次调用loadMoreClients 方法时,我都会尝试将新数据推送到我的clients 数组中。该出版物期待这个back_to 参数并且知道如何处理它。我的问题是我似乎无法从我的模板助手调用这些方法。
我将Iron 和Iron.controller 登录到控制台,它们都存在并且向我展示了我期望看到的内容。我似乎无法从我的模板帮助程序中找到有关如何访问 Iron.controller() 方法/属性的当前文档或示例
这是我的 RouteController 代码:
ClientController = ApplicationController.extend({
action : function(){
this.render(Router.current().route.getName())
},
data : function(){
if( this.params._id ){
return Clients.findOne({ _id:this.params._id })
}
},
waitOn : function(){
return [
Meteor.subscribe('directory'),
Meteor.subscribe('clients')
]
},
loadMoreClients : function(){
this.months_back += 3
this.back_to = moment().subtract(this.months_back,'months').startOf('day')
this.clients.push(Meteor.subscribe('clients', {back_to:this.back_to, skip:this.clients.length}))
},
loadAllClients : function(){
this.clients.push(Meteor.subscribe('clients', {back_to:this.start_of_time, skip:this.clients.length}))
},
// we'll use these properties to 'load more' client data
clients : [],
back_to : moment().subtract(3,'months').startOf('day'),
months_back : 3,
start_of_time : moment(new Date(0))
})
这是我的助手代码:
Template.client_list.helpers({
clients : function(){
var clients = []
Iron.controller().clients.forEach(function(client){
// ... some stuff here...
clients.push(client)
})
return clients
},
earliestClientLoaded : function(){
var controller = Iron.controller()
return controller.clients[controller.clients.length - 1].createdAt
}
})
Template.client_list.events({
'click .btn-load-more' : function(e){
e.preventDefault()
Iron.controller().loadMoreClients()
},
'click .btn-load-all' : function(e){
e.preventDefault()
Iron.controller().loadAllClients()
}
})
我的Iron.controller() 调用loadMoreClients 和loadAllClients 方法时遇到undefined function 错误。
我在这里做错了什么?
【问题讨论】:
标签: javascript node.js meteor iron-router meteor-blaze