首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在聚合物中做好准备之前,必须将属性设置为声明创建的子元素。

在聚合物中做好准备之前,必须将属性设置为声明创建的子元素。
EN

Stack Overflow用户
提问于 2017-01-05 00:07:24
回答 2查看 64关注 0票数 0

类似于这个问题,Init聚合物属性,但不完全一样。

在该子元素的就绪事件触发之前,是否有可能在聚合物中强制设置子元素的属性?

https://plnkr.co/edit/fM7lAflOLWOFuIiE7e9q?p=preview

index.html:

代码语言:javascript
复制
<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8" />
    <script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
    <link href="https://polygit.org/components/polymer/polymer.html" rel="import">
    <link href="user-profile.html" rel="import">
  </head>

  <body>
    <user-profile></user-profile>
  </body>

</html>

user-profile.html:

代码语言:javascript
复制
<link href="https://polygit.org/components/polymer/polymer.html" rel="import">
<link href="address-card.html" rel="import">

<dom-module id="user-profile">
  <template>
    <address-card address$="{{address}}"></address-card>
  </template>
  <script>
    Polymer({
      is: "user-profile",
      properties: {
        address: {
          type: String,
          value: "Pass the value to the child"
        }
      }
    });
  </script>
</dom-module>

地址-char.html:

代码语言:javascript
复制
<link href="https://polygit.org/components/polymer/polymer.html" rel="import">

<dom-module id="address-card">
  <template>
    {{content}}
  </template>
  <script>
    Polymer({
      is: "address-card",
      properties: {
        address: String
      },
      ready: function () {
        alert(this.address);
      }
    });
  </script>
</dom-module>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-07 02:52:11

元素<user-profile>,将值{{primaryAddress}}传递给他的子元素<address-card>。元素<user-profile>是一个“中介”,它控制/释放他的孩子的价值。

代码语言:javascript
复制
 <dom-module id="user-profile">
      <template>
        …
        <address-card address="{{address}}"></address-card>
      </template>
      … 
      properties: {
          address: {
          type: String,
          value: "Pass the value to the child"
          }
         }
    </dom-module>
票数 1
EN

Stack Overflow用户

发布于 2017-01-05 01:55:40

在这个场景中,我使用数据绑定系统将值从父传递给子节点。

用数据绑定连接路径

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41475298

复制
相关文章

相似问题

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