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

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

问题描述

我正在 ember.js 中开发一个应用程序.我有几个问题要问你们所有人.先说说我的申请要点,然后说说我面临的问题.

  1. 应用程序类似于auto cad"之类的绘图.为此,我使用 d3.js 库
  2. 出于绘图目的,我们有不同的部分,如火、水等.卫星所有这些部分都有不同的 svg 容器用于绘图.
  3. 在这件事之后,我有一个模块可以通过三种方式将此部分通过电子邮件发送到特定的电子邮件 ID

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

    3.2 一次将 PDF 中的所有部分 svg 内容.(这里是我的实际问题开始)

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

我像这样创建了我的路线

emailPDF = Ember.Route.extend({setupController:功能(控制器,模型){alert("控制器设置");this.controllerFor('fire').set('model', model);this.controllerFor('gas').set('model', model);},渲染模板:函数(){this._super();this.render('fire', {//要渲染的模板into: 'emailPDF',//要渲染的模板outlet: 'fire',//该模板中的出口名称controller: 'fire'//用于模板的控制器});this.render('gas', {进入:'emailPDF',出口:'气体',控制器:'气体'});}});

模板就像:

{{出口'火'}}

<div id="gas_test">{{出口'气体'}}

然后我像这样从一个控制器转换这条路线:

this.transitionToRoute('emailPDF');

但是在 allSections 模板中,我得到了以前的模板,我已经在火和煤气出口的地方打开了,无法渲染火和煤气模板.

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

解决方案

我相信你在这里想做的事情是这样的......你需要创建一条路线,比如 HomeAndContact.在这个路由中创建一个模板.您在这里有 2 个选项,使模板类似于:

{{outlet 'home'}}{{出口'联系'}}

或者你也可以这样做:

{{render 'home'}}{{呈现'联系'}}

我建议不要使用第二个选项,因为它会被弃用/与 Ember 正在做的事情不一致.

要执行第一个选项,您需要在 HomeAndContactRoute 中有一些这样的代码:

HomeAndContactRoute = Ember.Route.extend({设置控制器:功能(控制器,模型){this.controllerFor('home').set('model', model);this.controllerFor('contact').set('model', model);},渲染模板:函数(){this.render('home', {//要渲染的模板into: 'homeAndContact',//要渲染的模板outlet: 'home',//该模板中的出口名称controller: 'home'//用于模板的控制器});this.render('联系人', {进入:'homeAndContact',出口:'联系',控制器:'联系'});}});

我希望这会有所帮助.

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天全站免登陆