dart - polymer Dart 传递元素作为属性

标签 dart polymer dart-polymer

感觉,我一个月前对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/

相关文章:

dart - 为什么 `if (var = null)` 在 dart 中编译?

javascript - dom-repeat 中的项目更改未传达给其他项目

dart - Polymer Dart @observable 不同的行为

jquery - 如何将 jquery ui 小部件嵌入到polymer-dart web 组件中

dart - 如何在没有用户交互的情况下发送短信?

ios - 从字典访问 FlutterStandardTypedData 时出现 "[__NSArrayI data]: unrecognized selector"

Flutter 搜索带有空格的希伯来语(从左到右)联系人不起作用

javascript - polymer 动画获取关键帧错误

css - Polymer 2 从外部样式表为元素的子节点设置样式

dart - 如何在 Dartium 中显示膨胀的聚合物元素?