Ember js:在一页上加载数据的多个模板 [英] Ember js : load multiple template on one page with data

查看:68
本文介绍了Ember js:在一页上加载数据的多个模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ember.js中的应用程序。我有几个问题给大家。首先让我讨论我的应用程序,然后讨论我面临的问题。


  1. 应用程序是关于像汽车卡。为此,我使用d3.js库

  2. 为了绘图目的,我们有不同的部分,如Fire,Water等.Satelite所有这些部分都有不同的svg容器用于绘图。 / li>
  3. 在这些事情之后,我有一个模块用于电子邮件,这部分以三种方式使用特定的电子邮件ID



    3.1当前部分明智的电子邮件(如果我们在一个火灾部分,那么如果我们发送电子邮件,那么svg的火灾部分将以pdf的形式发送)(完成)



    3.2在时间所有部分svg内容的PDF。 (这里我的实际问题开始)


在这一点上,所有部分电子邮件我正在检索所有部分svg的问题一次因为当前部分已经加载到视图中,所以模板带有数据,但是如何获取所有的部分模板及其绘图数据(svg元素)。



我创建我的路线这样

  emailPDF = Ember.Route.extend({

setupController:function(controller ,model)
{
alert(Controller setup);
this.controllerFor('fire')。set('model',model);
this.controllerFor 'gas')set('model',model);
},
renderTemplate:function(){
this._super();
this.render ',{//将
渲染为:'emailPDF'的模板,//将模板渲染成
outlet:'fire',//该模板中的插座名称
控制器:'fire'//控制器用于模板
});
this.render('gas',{
进入:'emailPDF',
出口:'gas',
控制器:'gas'
});
}
});

模板如下:

 < div id =fire_test> 
{{outlet'fire'}}
< / div>
< div id =gas_test>
{{outlet'gas'}}
< / div>

然后我从一个控制器转换此路由,如下所示:

  this.transitionToRoute('emailPDF'); 

但是,在allSections模板中,我已经取消了之前已经在火灾中打开的模板和气体出口不能渲染火和气体模板。



请告诉我,如果我做错了...

解决方案

我相信你想在这里做的是这样的...你需要创建一个路由,说HomeAndContact。在此路由中创建一个模板。您有两个选项,使模板类似于:

  {{outlet'home'}} 
{ outlet'contact'}}

或者你也可以做:

  {{render'home'}} 
{{render'contact'}}

我建议反对第二个选项,因为它将被弃用/不符合Ember正在进行的工作。



要做第一个选项,您需要在HomeAndContactRoute中使用一些代码:

  HomeAndContactRoute = Ember.Route.extend({
setupController:function(controller,model){
this.controllerFor('home')。set('model',model );
this.controllerFor('contact')。set('model',model);
},
renderTemplate:function(){
this.render ',{//将
呈现为:'homeAndContact'的模板,//将模板渲染为
outlet:'home',//模板中的插座名称
控制器:'home'//控制器用于模板
});
this.render('contact',{
into:'homeAndContact',
outlet: 'contact',
controller:'contact'
});
}
});

我希望这有帮助。


I am working on a application in ember.js . I have an few questions to all of you guys. First lets discuss about my application points and then what problem I am facing in.

  1. Application is about something like a drawing a plans like a "auto cad ". For this purpose I am using d3.js library
  2. For a drawing purpose we have different sections like Fire, Water, etc..Satelite All of this sections have different svg container for drawing.
  3. After this things I have one module for email this sections to a particular email id in three ways

    3.1 Current Section wise email (Means if we drawing in a fire section then If we send email then svg of fire section will send as a form of pdf) (Done)

    3.2 At a time all the sections svg content in PDF. (Here my actual problem starts)

In this point all sections email I am getting problem in retrieve all section svg's at a time. Because the current section is already loaded in a view, template with data , But how can I get all the sections template with its drawing data (svg element's).

I created my route like this

emailPDF = Ember.Route.extend({

    setupController: function(controller, model)
    {
        alert("Controller setup");
        this.controllerFor('fire').set('model', model);
        this.controllerFor('gas').set('model', model);
    },
    renderTemplate: function() {
        this._super();
        this.render('fire', {           // the template to render
            into: 'emailPDF',       // the template to render into
            outlet: 'fire',              // the name of the outlet in that template
            controller: 'fire'        // the controller to use for the template
        });
        this.render('gas', {
            into: 'emailPDF',
            outlet: 'gas',
            controller: 'gas'
        });
    }
});

And the template is like :

<div id="fire_test">
    {{outlet 'fire'}}
</div>
<div id="gas_test">
    {{outlet 'gas'}}
</div>

Then I transition this route from one controller like this :

this.transitionToRoute('emailPDF');

But here in the allSections template I am getting previous template that I have already open in the place of fire and gas outlet not able to render fire and gas template.

Please tell me if i am doing something wrong...

解决方案

I believe what you want to do here is something like this... You need to create a route, say HomeAndContact. In this route create a template. You have 2 options here, make the template something like:

{{outlet 'home'}}
{{outlet 'contact'}}

Or you could also just do:

{{render 'home'}}
{{render 'contact'}}

I would advise against the second option because it will be deprecated/is not aligned with what Ember is doing going forward.

To do the first option, you will need to have some code like this in your HomeAndContactRoute:

HomeAndContactRoute = Ember.Route.extend({
  setupController: function(controller, model) {
    this.controllerFor('home').set('model', model);
    this.controllerFor('contact').set('model', model);
  },
  renderTemplate: function() {
    this.render('home', {           // the template to render
      into: 'homeAndContact',       // the template to render into
      outlet: 'home',              // the name of the outlet in that template
      controller: 'home'        // the controller to use for the template
    });
    this.render('contact', {
      into: 'homeAndContact',
      outlet: 'contact',
      controller: 'contact'
    });
  }
});

I hope this helps.

这篇关于Ember js:在一页上加载数据的多个模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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