我正在更新以下路线:
App.SomeRoute = Ember.Route.extend({ events: { getMore: function(){ var controller = this.get('controller'),nextPage = controller.get('page') + 1,perPage = controller.get('perPage'),items; items = this.events.fetchPage(nextPage,perPage); controller.gotMore(items,nextPage); },fetchPage: function(page,perPage){ . . . . } } });
在很大程度上,它工作正常.但是,事件语法已被弃用.相反,我们假设使用动作.更新工作效果不错,直到我达到目标:
items = this.events.fetchPage(nextPage,perPage);
这会抛出错误:
TypeError: this.events is null
不幸的是,如果我将代码更新为:
items = this.actions.fetchPage(nextPage,perPage); => TypeError: this.actions is null
如何从同一路径中访问操作方法?
解决方法
你必须使用.send()来调用动作哈希中的函数.例:
App.SomeRoute = Ember.Route.extend({ actions: { getMore: function(){ var controller = this.get('controller'),items; items = this.send('fetchPage',nextPage,perPage); controller.gotMore(items,nextPage); },perPage){ .. . . } } });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。