ran*_*its 5 javascript ember.js
我试图访问needs在兄弟控制器上使用的控制器中的两个模型之一.我的路由器如下所示:
App.Router.map(function() {
this.route('login');
this.route('mlb.lineups', {path: 'tools/mlb/lineups'})
this.resource('mlb.lineups.site', { path: 'tools/mlb/lineups/site/:site_id' });
});
Run Code Online (Sandbox Code Playgroud)
该mlb.lineups路由定义如下所示:
App.MlbLineupsRoute = Ember.Route.extend({
model: function() {
var self = this;
return Ember.RSVP.hash({
sites: self.store.find('site')
})
},
setupController: function(controller, models) {
controller.set('model', models.get('sites'));
},
afterModel: function(models) {
var site = models.sites.get('firstObject');
this.transitionTo('mlb.lineups.site', site);
}
});
Run Code Online (Sandbox Code Playgroud)
我在这里使用Ember.RSVP.hash({})的原因是我计划在检索site模型后添加另一个要检索的模型.
现在MlbLineupsSiteController我在尝试sites使用以下内容访问模型:
App.MlbLineupsSiteController = Ember.ArrayController.extend({
needs: "mlb.lineups",
sites: Ember.computed.alias("controllers.models.sites")
});
Run Code Online (Sandbox Code Playgroud)
这是我在Ember控制台中遇到的错误: needs must not specify dependencies with periods in their names (mlb.lineups)
sites从MlbLineups我的控制器中获取模型的最佳方法是MlbLineupsSiteController什么?
Dan*_*mak 10
测试在Ember.js 1.10.0-beta.4.使用Controller中的以下代码引用嵌套控制器needs:
needs: ['classic/about']
Run Code Online (Sandbox Code Playgroud)
然后你可以使用以下方法访问它:
const aboutController = this.get('controllers.classic/about');
const aboutProperty = aboutController.get('customProperty');
Run Code Online (Sandbox Code Playgroud)
按预期工作.基本上你需要用斜线替换点.
| 归档时间: |
|
| 查看次数: |
610 次 |
| 最近记录: |