【发布时间】:2014-09-07 18:42:01
【问题描述】:
我有以下 core-elements 下拉元素,其中我使用 paper-item 而不是 core-item 来显示下拉标签。
// .html
<input required
id='birthday'
name='birthday'
type='date'
value="{{age.birthday}}"
on-change='{{inputHandler}}'>
<div layout horizontal>
<div layout vertical self-center
id='years-div'>Years
<core-dropdown disabled
id='years-core-ddwn'
halign="left"
label='0'
valueattr="label">
<template repeat="{{year in yearsList}}">
<paper-item id='years-ppr-itm' label="{{year}}"></paper-item>
</template>
</core-dropdown>
</div>
//.dart
var yearsList = <int>[ 1, 2, 3, 4]
@observable int year = 0;
class Age
{
int years = 0;
String birthday = '';
}
// calcualate age in years
void inputHandler()
{
if ( age.birthday != '' )
{
DateTime now = new DateTime.now();
DateTime birthday = DateTime.parse( age.birthday.replaceAll( r'-', '') );
//Duration dayz = ( birthday.difference( new DateTime.now() ) ).inDays;
Duration duration = new DateTime.now().difference( birthday );
// calculate years since birth
int days = duration.inDays;
age.years = days ~/ 365;
// attempting to set the PaperItem label to the calculated age
yearsPprItm = $[ 'years-ppr-itm' ] as PaperItem;
// neither of the following resets the PaperItem label to the age variable
yearsPprItm.setAttribute( 'label', age.years.toString() );
//year = age.years.toString();
}
下拉菜单正常显示,所选项目也正常检索。
没有错误堆栈跟踪,但使用 setAttribute 或将 age.years 分配给标签绑定到的可观察年份不会更改纸质项目标签。
我想知道绑定到迭代器变量是否非法。如果是这样,完成我想做的事情的正确方法是什么。
谢谢
【问题讨论】:
标签: dart dart-polymer