2013-07-09 4 views
0

엠버 선택 요소가 변경되면 어떻게 뷰 또는 템플릿 컨텐츠를로드 할 수 있습니까?변경 사항보기를 변경 하시겠습니까?

나는 엠버에게 거의 익숙하지 않습니다. 이것은 매우 쉬울 수도 있지만, 나는이 간단한 작업을 위해 너무 많이 고심하고 있습니다. 어떤 제안?

+0

코드를 표시 할 수 있습니까? – Raptor

+0

바이올린을 제공하면 도움이 될 수 있습니다 !!! – selvagsz

답변

2

@ intuitivepixel의 대답에 이어 다음은 선택 변경을 기반으로 템플릿을 동적으로로드하는 방법입니다.

//EMBER APP TEMPLATE 
App = Ember.Application.create(); 

App.ApplicationRoute = Ember.Route.extend({ 
    model: function(){ 
     return [ 
      {name: 'Kris', template: 'kris'}, 
      {name: 'Luke', template: 'luke'}, 
      {name: 'Alex', template: 'alex'} 
     ]; 
    } 
}); 

App.EmbeddedView = Ember.View.extend({ 
    templateName: Ember.computed.alias('controller.selected'), 
    templateNameDidChange: function() { 
    this.rerender(); 
    }.observes('templateName') 
}); 

<script type="text/x-handlebars"> 
    <h4>Load a view on ember select change?</h4> 
    {{view Ember.Select 
     contentBinding="this" 
     optionValuePath="content.template" 
     optionLabelPath="content.name" 
     valueBinding="selected" 
     prompt="Please select a name" 
    }} 
    <hr/> 
    {{view App.EmbeddedView}} 
</script> 
<script type="text/x-handlebars" id="luke"> 
    THE LUKE TEMPLATE 
</script> 
    <script type="text/x-handlebars" id="alex"> 
    THE ALEX TEMPLATE 
</script> 
    <script type="text/x-handlebars" id="kris"> 
    THE KRIS TEMPLATE 
</script> 

이 예제는 선택 상자에 따라 luke/alex/chris 템플릿을 전환합니다.

라이브 예제는이 jsbin을 참조하십시오. http://jsbin.com/uzekop/1/edit

+1

좋은 대답, 이것은 upvote받을 가치가있어 :) – intuitivepixel

+0

aw, thanks! 주위에 upvotes ... –

2

시도한 코드를 게시해야하지만 this example은 시작하는 데 도움이되므로 질문을 개선 할 수 있습니다.

선택 상자의 선택된 값에 따라 단추 레이블을 변경하는 방법에 대한 예제는 here을 참조하십시오.

희망이 있습니다.

관련 문제