2

私は emberjs を初めて使用し、マークアップで 2 つの異なるスクリプト タグを使用して 2 つのビューをレンダリングしようとしましたが、後者のビューのみがレンダリングされます。

HTML:

<script type="text/x-handlebars">
  {{view Ember.Select
         contentBinding="App.peopleController"
         selectionBinding="App.selectedPersonController.person"
         optionLabelPath="content.fullName"
         optionValuePath="content.id"}}

  <p>Selected: {{App.selectedPersonController.person.fullName}}
    (ID: {{App.selectedPersonController.person.id}})</p>
</script>
<script type="text/x-handlebars">
  {{#view Ember.Checkbox}}
    Check me!
  {{/view}}
</script>

ここでもフィドルを作成しました:jsfiddle

この場合、チェック ボックスは表示されますが、ドロップダウンの選択ビューは表示されません。

4

1 に答える 1

1

テンプレートの名前を指定する必要があります。名前のないテンプレートは ApplicationView のテンプレートと見なされます。名前のないテンプレートがいくつかある場合、ember は最後のテンプレートを選択します。したがって、次のようにする必要があります。

<script type="text/x-handlebars" data-template-name="check-box">
   {{#view Ember.Checkbox}}
     Check me!
   {{/view}}
</script>

ここに例がありますhttp://jsfiddle.net/zgLCr/419/ - Ember.Checkbox を別のビューにラップすることはあまり意味がありませんが、ビューに名前を付けてレンダリングする方法を示していますが、チェックボックスを内部に配置することはできますApplicationView のテンプレート:

<script type="text/x-handlebars">
   {{view Ember.Select
     contentBinding="App.peopleController"
     selectionBinding="App.selectedPersonController.person"
     optionLabelPath="content.fullName"
     optionValuePath="content.id"}}

   <p>Selected: {{App.selectedPersonController.person.fullName}}
      (ID: {{App.selectedPersonController.person.id}})</p>

   {{#view Ember.Checkbox}}
      Check me!
   {{/view}}
</script>
于 2013-01-09T10:18:44.847 に答える