感觉,我一个月前对Polymer 0.5提出的所有问题都再次由1.0提出...
我有一个自定义元素,该元素定义了一个属性,该属性我想采用一个Element以便以后可以使用它。
@HtmlImport('test_animation.html')
library test.animation
import 'dart:html';
import 'dart:js';
import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart' show HtmlImport;
import 'package:test/log.dart';
import 'dart:async';
// @jsProxyReflectable
@PolymerRegister('test-animation')
class TestAnimation extends PolymerElement {
@Property(observer: 'targetChanged')
Object target = null;
factory TestAnimation() => new Element.tag('test-animation');
TestAnimation.created() : super.created() {
Log.d(tag: 'Animation', message: 'Animation created with target "$target"');
}
//@eventHandler
@reflectable
void targetChanged([newValue, oldValue]) {
Log.d(tag: 'Animation', message: 'Target changed from "$oldValue" to "$newValue"');
Log.d(tag: 'Animation', message: 'Target is now "$target"');
}
}
我使用以下代码创建元素:<div id="buttonContainer">
<paper-button id="loginButton" on-click="login">Login</paper-button>
<paper-toast id="errorToast" text="Incorrect username or password."></paper-toast>
</div>
<test-animation target="{{$['loginButton']}}"></test-animation>
我的控制台输出是:Animation: Target changed from "null" to "null"
Animation: Target is now "null"
Animation: Animation created with target "null"
这是为什么?如何传递元素? -或者这还不可能吗?
最佳答案
从https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#path-binding:
The path syntax doesn’t support array-style accessors (such as users[0].name). However, you can include indexes directly in the path (users.0.name).
因此,您应该能够将
$['loginButton']
更改为$.loginButton
,然后它应该可以工作。
关于dart - polymer Dart 传递元素作为属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32287469/