2015-05-05 105 views
14

我正在使用ember.js中的應用程序。我有幾個問題給大家。首先讓我們討論一下我的申請要點,然後討論我面臨的問題。Ember js:使用數據在一頁上加載多個模板

  1. 應用程序就像一個像「自動CAD」一樣的圖紙。爲此,我正在使用d3.js庫
  2. 對於繪圖目的,我們有不同的部分,如火,水等等。衛星所有這些部分都有不同的svg容器供繪圖。
  3. 這事我有電子郵件一個模塊後,這部分到特定的電子郵件ID在三個方面

    3.1當前第明智的電子郵件(也就是說,如果我們在火節繪製然後如果我們發送電子郵件,然後火的SVG部分將作爲pdf的一種形式發送)(完成)

    3.2一次在PDF中的所有部分svg內容。 (這裏我的實際問題開始)

在這一點上所有部分電子郵件中檢索所有部分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('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' 
     }); 
    } 
}); 

而且模板是這樣的:

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

然後,我從一個控制器轉變這條路線是這樣的:

this.transitionToRoute('emailPDF'); 

但在這裏在allSections模板中,我得到了先前的模板,我已經在火和氣的地方打開了出口不能渲染火和氣模板。

請告訴我,如果我做錯了什麼......

+1

我真的很困惑這個問題。你想獲得所有這些小型的嵌入式應用程序,並將它們變成一個合適的應用程序,或者你想創建另一個應用程序來控制你的網站上的現有應用程序? – MilkyWayJoe

+1

感謝您的時間@MilkyWayJoe,請參閱例如讓我說有兩個鏈接「首頁」和「聯繫我們」。兩者有不同的看法,控制器,模板。而在這兩頁數據都來自數據庫。單獨它工作正常。但現在我想要在單個頁面中顯示這兩個頁面,但沒有鏈接,也沒有點擊。總之,我必須將所有這些東西合併到一個頁面中。就像這兩頁我有16個部分,我必須在一個頁面中顯示所有這些部分。其實我是初學者在ember.js –

+0

@MilkyWayJoe你需要一些代碼片段嗎? –

回答

4

我相信你想在這裏做什麼是這樣的事情......你需要創建一個路由,說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('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' 
    }); 
    } 
}); 

我希望這有助於。

+0

感謝您的時間@bmeyers!讓我試試這個 –

+0

Hi @bmeyers這個解決方案不起作用 –

+0

不工作怎麼樣?也許你可以提供更多的代碼,甚至更好的jsbin – bmeyers

相關問題