访问模板中的模型数据 [英] Accessing Model Data in Template

查看:77
本文介绍了访问模板中的模型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Router.map(function(){
this.route ('games',function(){
this.route('game',{path:'/:game_id'},function(){});
});
} );

当我访问路径 / games / 1 我必须访问这样的模型数据:

  {{model.title}} 

阅读文档,似乎控制器可以使模型数据没有模型前缀,所以我以为我可以这样做:

  {{title}} 

但是,如果没有 model ,则不起作用。我不是创建控制器,因为我不需要扩展这个特定的路由/模板。正在通过模型前缀准确访问模型数据?或者我可能会做一些其他的错误?

解决方案

您所指的文档是旧的,过去(1.13之前的iirc )控制器有一个模型代理,如果在控制器上没有找到模型,则可以查找模型上的属性。



由于引起混淆,这不再可用



新版本的 docs 不再引用 {{title}} 没有模型



如果您真的想使用它,而不使用模型前缀,您可以诉诸 Ember.computed.alias ,尽管我建议使用模型。,因为它更容易阅读和识别为模型属性vs控制器属性,特别是因为可路由组件设置为在不久的将来替换控制器(〜2.6)。


I have a route defined like so:

Router.map(function() {
    this.route('games', function() {
        this.route('game', {path: '/:game_id'}, function() {});
    });
});

When I visit path /games/1 I have to access the model data like so:

{{model.title}}

Reading the documentation, it seems that the controller would make the model data available without the model prefix so I thought I'd be able to do this:

{{title}}

But it doesn't work without model. I'm not creating the controller because I don't need to extend it for this particular route/template. Is accessing the model data via the model prefix accurate? Or am I possibly doing something else wrong?

解决方案

The docs you are referring to are old, in the past (pre 1.13 iirc) the controller had a model proxy that would look up properties on the model if they weren't found on the controller.

This is no longer available since it was causing confusion in the community.

The new versions of the docs no longer reference {{title}} without model.

If you really want to use it without the model prefix you could resort to Ember.computed.alias though I would recommend sticking with model. as it is easier to read and identify as a model property vs controller property, especially since routable components are set to replace controllers in the near future (~2.6).

这篇关于访问模板中的模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆