聚合物双向数据绑定

时间:2015-06-28 21:05:53

标签: polymer polymer-1.0

我有以下自定义元素。从简洁起见,我只包含相关的代码:

<dom-module id="my_custom_element">
    <template>
        ...
    </template>
</dom-module>
<script>
    Polymer({
        is: 'my_custom_element',
        properties: {
           selecteditem: {
                type: String,
                value: '',
                notify: false                
            }
        },
        //other functions
   });

请注意,selecteditem属性的notify字段设置为false。

以下是自定义元素的用法:

<my_custom_element id="myElement" selecteditem={{myselecteditem}}></my_custom_element>

如果某些内容导致selectedItem属性从自定义元素中更改,那么我希望以下警告语句不显示新值,因为notify设置为false。但实际行为是它显示新值。这是为什么?

alert($('#myElement').prop('selecteditem'));

在以下文章中:

https://www.polymer-project.org/1.0/docs/devguide/data-binding.html

明确指出:

“如果绑定的属性没有设置通知标志,则只会发生单向(向下)绑定”。

但是我在这种情况下遇到了“向上”的约束。

1 个答案:

答案 0 :(得分:0)

我可能错了,但我认为你所看到的是upward绑定。

无论是否启用双向绑定,my-custom-element上的属性都会发生变化,但不会向上传播到父my-parent-element

myPropmy-parent-element中的selectedItem不会在<dom-module id="my-parent-element"> <template> <my-custom-elment selecteditem={{myProp}}> </template> </dom-module> 更改时更新。

if (indexCount < parseInt(current)) {
相关问题