鉴于这段 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>
对于我想要的任何属性,我如何将其变成可重用的部分?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"}}
// controllers/input.js
Application.InputController = Ember.ObjectController.extend({
type: "text"
});
// views/input.js
Application.InputView = Ember.View.extend({
templateName: "form/input"
});
<!-- templates/form/input.hbs -->
<input {{bindAttr id="id" name="name" type="type" placeholder="placeholder"}}>