首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在聚合物飞镖中,从父母到孩子的沟通方式是什么?

在聚合物飞镖中,从父母到孩子的沟通方式是什么?
EN

Stack Overflow用户
提问于 2013-12-02 11:57:30
回答 2查看 429关注 0票数 2

为了在孩子和父母之间交流,事件似乎是最优雅的方式。父母与孩子之间的沟通有哪些选择?

更具体地说,当子方法变得可见时,我想要它调用它。这些都是我想出的点子:

  • xtag -优雅和工作
  • 观察‘隐藏’-没有设法做到这一点,隐藏是没有标记为可观察的元素
  • 在子元素中发布触发器变量,并在父-丑陋中绑定和更改它。

还有其他选择吗?

EN

回答 2

Stack Overflow用户

发布于 2013-12-02 12:28:37

我还没有试过,但是也许MutationObserver能做你想做的事。

Seth的聚合物示例包含两个示例:第一个例子是onMutation事件element.dart

代码语言:javascript
运行
复制
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');
    });
  }
}

第二个示例使用MutationObserver类element.dart

===编辑===

你试过链接的例子了吗?“观察”方法允许指定应观察的内容:

代码语言:javascript
运行
复制
  /**
   * 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}) {
票数 0
EN

Stack Overflow用户

发布于 2015-07-19 06:07:44

为了从父母的聚合物到儿童的聚合物,这个解决方案对我有好处。

如果我们有这样的儿童聚合物元素:

代码语言:javascript
运行
复制
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() {
  }

  myCustomMethod(param){
    print("pass-in param = $param");
  }

}

要从父元素访问子元素,请执行以下操作:

  1. 查询父元素中的子聚合物元素(是的,首先访问HTML元素)
  2. 将其转换为绑定类(在本例中为ex: MyElement.dart )
代码语言:javascript
运行
复制
  (theParentClass.querySelector("my-element") as MyElement).myCustomMethod({"done":true});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20327749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档