Ember renderTemplate继电器模型 [英] Ember renderTemplate relay model

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

问题描述

我的Ember应用程序在这里努力工作,并且一直很好。但是,我遇到了一个意想不到的行为问题,我不知道有关这个问题的最佳方法。



问题是在特定路由中,我想再一条路线进入另一个出口。但是,另一个引入另一个插座的路线并不保留它自己的模型。



如果我这样做:

  App.TestRoute = Ember.Route.extend({
model:function(){
return {
标题:Test,
testContent:这是测试。
}
}
});

App.IndexRoute = Ember.Route.extend({
renderTemplate:function(){
this.render(test,{
outlet:left
});

this.render({
outlet:right
});
},

model:function(){
return {
heading:Index,
indexContent:这是索引。
}
}
} );

...并访问 IndexRoute 我希望将 TestRoute 的模型呈现在 TestRoute 的模板中,但只有 IndexRoute 的模型被转发到两个模板。



Fiddle here
http://jsfiddle.net/3TtGD/1/



如何让Ember将路由使用默认模型,而无需表达合并他们?似乎很乏味。



此外,具有某些模型属性的相同名称,如 {{heading}}



解决这个问题最好的方法是什么?



谢谢你的时间



最好的问候,
dimhoLt

解决方案

您正在告诉Ember在插座中呈现模板的 renderTemplate 方法,但它只会将控制器默认为管理路由的控制器。鉴于控制器处理路由是有道理的,它管理该路由中的所有模板。



当然,您可以使用以下命令指定其他控制器:

  this.render(test,{
outlet:left,
controller:'test'
});

它可以反过来是一个你已经实例化的控制器(也可能设置它的内容):

  var testController = this.controllerFor('test'); 
testController.set(....)
this.render(test,{
outlet:left,
controller:testController
});关于使用模型:您可以调用 this.modelFor('test'), ),它将返回 test route的模型(它甚至知道它是否已经解决)。当我需要访问其中一个父路由的模型时,我通常会这样做。



我认为访问父路由的模型是有意义的,但是如果您访问不相关路由的模型,则不太重要。你为什么不想要 merge 这两个模型?


Working hard on my Ember app here, and it's going along fine. However, I've run into an issue of unexpected behaviour and I'm not sure regarding the best approach to this problem.

The problem is that in a specific route, I want to render another route into another outlet. However, the other route that I render into the other outlet doesn't retain it's own model.

If I do this:

App.TestRoute = Ember.Route.extend({
    model: function() {
        return {
            heading: "Test",
            testContent: "This is test."
        }
    }
});

App.IndexRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render("test", {
            outlet: "left"
        });

        this.render({
            outlet: "right"
        });
    },

    model: function() {
        return {
            heading: "Index",
            indexContent: "This is index."
        }
    }
});

... and access the IndexRoute, I would expect the TestRoute's model to be rendered into the TestRoute's template, but only the IndexRoute's model is relayed to both templates.

Fiddle here: http://jsfiddle.net/3TtGD/1/

How do I allow Ember to use the default model for a route without having to expressively merge them? It seems tedious.

Also, having the same name of some model properties, like {{heading}} is desirable, but not necessary.

What's the best approach for solving this issue?

Thank you for your time.

Best regards, dimhoLt

解决方案

In the renderTemplate method you're telling Ember to render a template inside an outlet but it will just default the controller to the one managing the route. Given it's the controller handling the route it makes sense that it manages all the templates within that route.

Of course you can specify a different controller using:

this.render("test", {
    outlet: "left",
    controller: 'test'
});

it can in turn be a controller you already instantiated (and maybe set its content):

var testController = this.controllerFor('test');
testController.set(....)
this.render("test", {
    outlet: "left",
    controller: testController
});

About using the model: You can call this.modelFor('test') inside the route and it will return the model of the test route (it even knows if it has already been resolved). I usually do this when I need to access the model of one of the parent routes.

I believe it makes sense to access the model of a parent route, but not so much if you're accessing the model of an unrelated route. Why don't you want to merge both models?

这篇关于Ember renderTemplate继电器模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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