3.9 Templates -- Input Helpers

本文介绍Ember.js框架中表单控件的使用方法,包括{{input}

一、Input Helpers

Ember中{{input}}{{textarea}}是创建常规表单控件最简单的方法。

{{input}}包裹内建的Ember.TextFieldEmber.Checkbox视图,然而{{textarea}}包裹Ember.TextArea。使用这些辅助器,你可以用这些声明创建这些视图,和你直接创建<input><textarea>几乎相同。

二、Text Fieleds

{{input value="http://www.facebook.com"}}

HTML:

<input type="text" value="http://www.facebook.com"/>

你可以向input helper传递下面这些标准的<input>属性:

`readonly``required``autofocus`
`value``placeholder``disabled`
`size``tabindex``maxlength`
`name``min``max`
`pattern``accept``autocomplete`
`autosave``formaction``formenctype`
`formmethod``formnovalidate``formtarget`
`height``inputmode``multiple`
`step``width``form`
`selectionDirection``spellcheck` 

如果这些属性被字符串包括,它们的值将被直接设置到元素上。如果没有引号,这些值将被绑定到模板当前渲染上下文的一个属性。

example:

{{input type="text" value=firstName disabled=entryNotAllowed size="50"}}

将绑定disalbed属性绑定到当前上下文中entryNotAllowed 值。

三、Actions

为一个action派遣一个特定事件,例如enter或者key-press

{{input value=firstName key-press="updateFirstName"}}

四、CheckBoxes

你也可以通过设置type,使用{{input}}去创建一个checkbox。

{{input type="checkbox" name="isAdmin" checked=isAdmin}}

Checkboxes支持以下属性:

  • checked
  • disabled
  • tabindex
  • indeterminate
  • name
  • autofocus
  • form

它可以绑定或设置如前一节中所述。

五、Text Areas

{{textarea value=name cols="80" rows="6"}}

将会绑定textarea的值到当前上下文中的name

{{textarea}}支持下面属性:

  • value
  • name
  • rows
  • cols
  • placeholder
  • disabled
  • maxlength
  • tabindex
  • selectionEnd
  • selectionStart
  • selectionDirection
  • wrap
  • readonly
  • autofocus
  • form
  • spellcheck
  • required

转载于:https://www.cnblogs.com/sunshineground/p/5153167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值