1

在 Ember 指南http://emberjs.com/guides/中的 EmberJs 入门教程的大约 17:23 分钟,教程作者在模板中包含一个部分,使用格式{{partial 'post/edit'}}调用部分并指示它应该在哪里包括,然后他给出了包含这种风格的 id 的部分

id="post/_edit"

我在此代码中复制了该模式,但部分未包含在法院列表中。有什么我做错了吗?据我了解,我只需要在 Handlebars 中指出我包含了一个部分,而不是在 Ember 视图或控制器中做任何事情来使其工作。

<script type="text/x-handlebars" id="courts">

  <div class='span4'>
      {{#each item in model}}
      <li> {{#link-to 'court' item}}
      {{ item.name }} 
      {{ partial 'courts/blah'}}
      {{/link-to }}</li>
    {{/each}}

         </ul>
  </div>

  <div class="span4 offset4">
   {{ outlet}}
   </div>

</script>

 <script type="text/x-handlebars" id="courts/_blah">
    This is a partial  blah blah
 </script>

EmberJS 教程中的代码。

  <script type="text/x-handlebars" id="post">
    {{#if isEditing}}
      {{partial 'post/edit'}}
      <button {{action 'doneEditing'}}>Done</button>
    {{else}}
      <button {{action 'edit'}}>Edit</button>
    {{/if}}


  </script>

  <script type="text/x-handlebars" id="post/_edit">
    <p>{{input type="text" value=title}}</p>
    <p>{{input type="text" value=excerpt}}</p>
    <p>{{textarea value=body}}</p>
  </script>
4

1 回答 1

1

通常你想使用data-template-name而不是id命名你的模板。

<script type="text/x-handlebars" data-template-name="application">
  <!-- Stuff goes here. -->
</script>
于 2013-09-25T20:48:53.213 回答