【问题标题】:call method in Iron-Router RouteController from Template.tmpl.helpers() not working从 Template.tmpl.helpers() 调用 Iron-Router RouteController 中的方法不起作用
【发布时间】:2014-12-01 08:55:28
【问题描述】:

每次调用loadMoreClients 方法时,我都会尝试将新数据推送到我的clients 数组中。该出版物期待这个back_to 参数并且知道如何处理它。我的问题是我似乎无法从我的模板助手调用这些方法。

我将IronIron.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() 调用loadMoreClientsloadAllClients 方法时遇到undefined function 错误。

我在这里做错了什么?

【问题讨论】:

    标签: javascript node.js meteor iron-router meteor-blaze


    【解决方案1】:

    我已经改变了解决这个问题的方法,只需更新订阅以订阅早于当前加载日期的帖子。

    它正在工作,虽然似乎应该有比在我想加载更多内容时必须waitOn 订阅更好的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-09
      • 2015-02-23
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多