简体   繁体   English

Ember.js查看和参数

[英]Ember.js View and params

I have an Ember.js route like this: 我有一条Ember.js这样的路线:

this.route 'doc', path: '/docs/:doc'

And I need to set the template based on the :doc param. 我需要根据:doc param设置模板。 How can I achieve this? 我怎样才能做到这一点?

Thanks. 谢谢。

Maybe you could try something like this: 也许你可以尝试这样的事情:

  1. Set the desired templateName into your context/model in the property "templateName". 在“templateName”属性中将所需的templateName设置到上下文/模型中。
  2. In the View for your route access the context of the View (= your model) and read the property and set it as templateName of the View. 在路径视图中访问View(=您的模型)的上下文并读取属性并将其设置为View的templateName。

App.DocView = Ember.View.extend({
    render : function(buffer){
      var context = this.get("context.content");
      this.set("templateName", context);
      this._super(buffer);
    }
});

Link to Fiddle: http://jsfiddle.net/mavilein/DQ8gS/2/ 链接到小提琴: http//jsfiddle.net/mavilein/DQ8gS/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM