Polymer1.0中动态设置disabled
2015-10-22 14:08
260 查看
我想在下面这个button上动态绑定一个disabled,是的这个button在满足某些条件时显示,不满足时隐藏。
问题就在于disabled是一个boolean,不是字符串。所以当我第一开始写成
的时候,这个button不论item.disabled是true还是false都会显示出来。
后来在网上搜到这个http://stackoverflow.com/a/23822215/2177408
里面提了两种解决方法,一种是disabled?="{{item.disabled}}",一种是disabled$="{{item.disabled}}"。经过测试,只有第一种有效。
http://stackoverflow.com/a/23822215/2177408
Binding to the disabled attribute can be done like this:
This
special syntax introduced by Polymer to support binding to this kind of boolean attributes.
This does not work:
Because it would result in
which would still disable the button.
For Polymer >= 1.0 the new syntax to use is:
Note:
has to be a boolean as Marco pointed out below. Otherwise you have to create a function that would return
and Migration Guidehere for reference.
<paper-button class="green approveButton" on-click="reviewArt" data-version="{{item.version}}">Approve</paper-button>
问题就在于disabled是一个boolean,不是字符串。所以当我第一开始写成
disabled="{{item.disabled}}"
的时候,这个button不论item.disabled是true还是false都会显示出来。
后来在网上搜到这个http://stackoverflow.com/a/23822215/2177408
里面提了两种解决方法,一种是disabled?="{{item.disabled}}",一种是disabled$="{{item.disabled}}"。经过测试,只有第一种有效。
http://stackoverflow.com/a/23822215/2177408
Binding to the disabled attribute can be done like this:
<button ... disabled?="{{ points == 0 }}">Content</button>
This
?is
special syntax introduced by Polymer to support binding to this kind of boolean attributes.
This does not work:
<button ... disabled="{{ points == 0 }}">Content</button>
Because it would result in
<button ... disabled="false">Content</button>
which would still disable the button.
For Polymer >= 1.0 the new syntax to use is:
<button ... disabled$="{{value}}">Content</button>
Note:
valuealready
has to be a boolean as Marco pointed out below. Otherwise you have to create a function that would return
points == 0. See Data Binding Documentation here
and Migration Guidehere for reference.
相关文章推荐
- iOS 单例的标准写法
- Android Color 颜色过度计算实现方法
- 输出时间对应的人数
- 从小学到高中,一个程序猿的独白
- Android 百度地图开发(二)
- IPC机制之三:IPC方式(Bundle、文件共享、Messenger)
- js简单实现国际化
- android反编译
- JSP HTML error code
- MindMapper中怎么实现便笺的添加
- HashSet的用法
- Core Data入门
- Autolayout让你界面适配飞起来
- Android 操作系统的内存回收机制
- NSArray和NSDictionary中存放nil的处理
- SPOJ QTREE 1-3题解
- UFT 01
- Cisco Unified CME 7.1 Supported Firmware, Platforms, Memory, and Voice Products
- 五大常用算法:分治、动态规划、贪心、回溯和分支界定
- sicily 1317. Sudoku