簡體   English   中英

Polymer-Dart 將元素作為屬性傳遞

[英]Polymer-Dart passing Elements as property

感覺就像,我一個月前對 Polymer 0.5 提出的所有問題都在 1.0 中再次出現......

我有一個自定義元素,它定義了一個屬性,我想將其作為一個元素,以便我以后可以使用它。

@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>

我的控制台輸出是:

動畫:目標從“空”變為“空”

動畫:目標現在為“空”

動畫:用目標“null”創建的動畫

這是為什么? 如何傳遞元素? - 或者這還不可能嗎?

來自https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#path-binding

路徑語法不支持數組樣式的訪問器(例如 users[0].name)。 但是,您可以直接在路徑 (users.0.name) 中包含索引。

因此,您應該能夠將$['loginButton']更改$['loginButton'] $.loginButton然后它應該可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM