如何在ember.js中为重复标记创建可重用的部分?

kra*_*ene 8 partial-views reusability ember.js

鉴于这一块HTML:

<div id="email_field" class="control-group">
  <label class="control-label" for="account.email">Email</label>
  <div id="email_input" class="controls">
    <input id="account.email" name="account.email" type="text" placeholder="jpublic@example.com">
    <span class="help-block">We just need a valid email address.</span>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

对于我想要的任何属性,如何将其转换为可重用的部分?IE:电子邮件,密码,密码确认等

我会假设某种视图层次结构,但我不太确定.

编辑:经过进一步的探索,我已经淘汰了{{view}},{{render}}并弄清楚我需要什么:

我想:1.使用特定的视图(InputView)2.使用特定的控制器(最好类似命名:InputController)({{view}}我认为不这样做)3.能够多次使用({{render}}不能这样做) )4.能够传入值({{render}}不能这样做)

例:

<!-- templates/application.hbs -->
{{foo "input" name="Email" id="account.email" placeholder="jpublic@email.com"}}
Run Code Online (Sandbox Code Playgroud)
// controllers/input.js
Application.InputController = Ember.ObjectController.extend({
  type: "text"
});
Run Code Online (Sandbox Code Playgroud)
// views/input.js
Application.InputView = Ember.View.extend({
  templateName: "form/input"
});
Run Code Online (Sandbox Code Playgroud)
<!-- templates/form/input.hbs -->
<input {{bindAttr id="id" name="name" type="type" placeholder="placeholder"}}>
Run Code Online (Sandbox Code Playgroud)

Wil*_*ney 3

我将创建一个包含所有可变参数的视图。例如:

{{view App.FormEntity
    name="email"
    placeholder="My placeholder..."
    help="We just need a valid email address."
    valueBinding="value"
}}
Run Code Online (Sandbox Code Playgroud)

从那里您可以提取标签、各种类名称,然后用于Ember.TextField将值绑定到。

bindAttr将所有这些参数传递到视图中后,使用s、几个计算属性和 Ember 帮助器(例如 )的混合来创建标记应该很容易Ember.TextField