advanced data binding in Polymer

旧巷老猫 提交于 2019-12-12 03:45:25

问题


i have a little problem that i can not solve on my own. I have custom element:

<dom-module id="station">
   <template>
     <country-iso-alpha3 id="country" selected={{country}}></country-iso-alpha3>
   </template>

this custom element station has country property with CZE default value.


if we look in country-iso-alpha3 :

<paper-dropdown-menu>
    <paper-menu class="dropdown-content" attr-for-selected="type" selected="{{selected}}" >
        <paper-item type="CZE">
            <span>CZE</span>
        </paper-item>
        <paper-item type="ENG">
            <span>ENG</span>
        </paper-item>
    </paper-menu>
</paper-dropdown-menu>

properties of country-iso-alpha3 are:

properties: {
    label: {},
    selected: {},
},

what i am trying to achieve is that when user tap on paper item inside paper menu, property country in station element should update. But the only thing that is updated is selected attribute in station

Is there any way how to achieve this? Maybe this is already 3 way data binding.

I know, my english is not best and this is not so easy to demonstrate so if you do not undestand i can try to explain it a little bit better


回答1:


In your country-iso-alpha3 element, configure selected to propagate changes upward. This can be done by setting notify: true.

properties: {
    selected: {
        type: String,
        notify: true
    }
},

By default, changes are not propagated to the parent element (docs).



来源:https://stackoverflow.com/questions/39918908/advanced-data-binding-in-polymer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!