【问题标题】:Polymer: Two Way Binding to a Child Element Inside a Dom-Repeat Template聚合物:在 Dom-Repeat 模板中以两种方式绑定到子元素
【发布时间】:2015-10-26 11:17:00
【问题描述】:

我对与聚合物中的数组进行数据绑定感到非常困惑,我认为这是一个非常简单的用例。

我有一个元素,具有一个数组作为属性,我想为数组中的每个项目显示一个子元素列表。

<dom-module id="parent-element">
    <template>
        <h1>This is the parent!</h1>
        <template is="dom-repeat" items="{{arrayproperty}}" as="item">
            <child-element
                propertyone="{{item.propertyone}}"
                propertytwo="{{item.propertytwo}}">
            </child-element>
        </template>
    </template>
</dom-module>

这段代码很好用。创建适当数量的子元素,并将数组中的属性传递给子元素。但是,当子元素属性发生更改时,这些更改不会传递回父元素数组属性。如何使用双向绑定配置此设置,以便父元素从子元素获取更新?

【问题讨论】:

    标签: javascript arrays data-binding polymer


    【解决方案1】:

    确保在子元素的属性定义中设置notify: true

    来自docs

    如果true,则该属性可用于双向数据绑定。

    【讨论】:

    • 谢谢。我知道。我只是个白痴,没想到。
    猜你喜欢
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多