2013-09-06 13 views
6

Ich bin zu ember neu und versuche herauszufinden, wie man eine Schablone rendert, wenn sich ein auserwähltes Steuerelement ändert.EmberJS: Wie man eine Schablone auf Auswahländerung rendert

Code:

App.LocationTypeController = Ember.ArrayController.extend({ 

    selectedLocationType: null, 

    locationTypeChanged: function() { 
     //Render template 
    }.observes('selectedLocationType') 
}); 

{{view Ember.Select 
    contentBinding="model" 
    selectionBinding="selectedLocationType" 
    optionValuePath="content.id" 
    optionLabelPath="content.name"}} 

Wenn die location ändert die locationTypeChanged Funktion in der Steuerung ausgelöst wird. Aber wie rende ich etwas Inhalt in das Dom von dort? (This.render()?) ...

Antwort

7

Ja müssen Sie nur this.render() verwenden, aber der Schlüssel hier ist into Option drin.

App.LocationTypeController = Ember.ArrayController.extend({ 

selectedLocationType: null, 

locationTypeChanged: function() { 
    var selectedLocationType = this.get('selectedLocationType'); 
    this.send('changeTemplate',selectedLocationType); 
}.observes('selectedLocationType') 
}); 

Haben Sie die Aktion in Ihrem Weg als

changeTemplate: function(selection) { 
      this.render('template'+selection.id,{into:'locationType'}); 
} 

und haben eine {{outlet}} in Ihrer locationType ‚s Vorlage.

{{view Ember.Select 
     contentBinding="model" 
     selectionBinding="selectedLocationType" 
     optionValuePath="content.id" 
     optionLabelPath="content.name"}} 

{{outlet}} 

Probe JSBin für Ihre Anforderung

4

Wenn Sie nur eine frament zeigen müssen, wenn etwas ausgewählt existieren, können Sie die if Lenker Helfer verwenden:

in Ihrer Vorlage

... 

{{#if selectedLocationType}} 
    Any content here will be visible when selectedLocationType has some value 
{{/if}} 

... 

{{view Ember.Select 
    contentBinding="model" 
    selectionBinding="selectedLocationType" 
    optionValuePath="content.id" 
    optionLabelPath="content.name"}} 

Ich hoffe, es hilft

Verwandte Themen