2

子供から親へのコミュニケーションには、イベントが最もエレガントな方法のようです。親から子へのコミュニケーションにはどのような選択肢がありますか?

より具体的には、子が表示されたときに呼び出されるメソッドが必要です。これらは私が思いついたアイデアです:

  • xtag - エレガントで機能します
  • 「hidden」の観察 - これを機能させることができませんでした。非表示は要素で観察可能としてマークされていません
  • 子でトリガー変数を公開し、親でバインドして変更する - 醜い

他のオプションはありますか?

4

2 に答える 2

0

私はまだ試していませんが、おそらくMutationObserverはあなたが望むことをします。

Seth Ladd のポリマーの例には 2 つの例が含まれてい ます。

library my_element;

import 'package:polymer/polymer.dart';
import 'dart:html';
import 'dart:async';

@CustomTag('my-element')
class MyElement extends PolymerElement {
  MyElement.created() : super.created() {

    // NOTE this only fires once,
    // see https://groups.google.com/forum/#!topic/polymer-dev/llfRAC_cMIo
    // This is useful for waiting for a node to change in response
    // to some data change. Since we don't know when the node will
    // change, we can use onMutation.
    onMutation($['list']).then((List<MutationRecord> records) {
      $['out'].text = 'Change detected at ${new DateTime.now()}';
    });

    new Timer(const Duration(seconds:1), () {
      $['list'].children.add(new LIElement()..text='hello from timer');
    });
  }
}

2 番目の例では、MutationObserver クラスを使用してい ます https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/mutation_observers/my_element.dart

=== 編集 ===

リンクされた例を試しましたか?observe メソッドを使用すると、何を観察するかを指定できます。

  /**
   * Observes the target for the specified changes.
   *
   * Some requirements for the optional parameters:
   *
   * * Either childList, attributes or characterData must be true.
   * * If attributeOldValue is true then attributes must also be true.
   * * If attributeFilter is specified then attributes must be true.
   * * If characterDataOldValue is true then characterData must be true.
   */
  void observe(Node target,
               {bool childList,
                bool attributes,
                bool characterData,
                bool subtree,
                bool attributeOldValue,
                bool characterDataOldValue,
                List<String> attributeFilter}) {
于 2013-12-02T12:28:37.047 に答える