简体   繁体   English

聚合物数据绑定-

[英]Polymer data binding -

Can someone tell me where i'm going wrong? 有人可以告诉我我要去哪里错吗? I have an element system-menu that queries for data using iron-ajax then i'm supposed to bind that data to my template. 我有一个元素系统菜单 ,使用Iron-ajax查询数据,然后将这些数据绑定到我的模板。

<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-menu-behavior/iron-menubar-behavior.html">

<dom-module id="system-menu">
    <template>
    <iron-ajax
        auto
        url="{{url}}"
        params='{"ajax":"true"}'
        handle-as="json"
        on-response="dataLoaded"
        debounce-duration="300">
    </iron-ajax>
    <div class="content"><content></content></div>
</template>

</dom-module>

<script>
    (function() {
        Polymer({
            is: 'system-menu',
            behaviors: [
                Polymer.IronMenubarBehavior
            ],
            ready: function() {
            },
            properties: {
                data: {
                    type: Object,
                    reflectToAttribute: true,
                    notify: true
                }
            },
            attached: function () {
                this.data = [];
            },
            dataLoaded: function (data) {
                this.data = data.detail.response;
            }
        }); 
    })();
</script>

` `

This is how I use the element, 这就是我使用元素的方式

<link rel="import" href="/themes/_components/custom_components/system-menu/system-menu.html">

    <system-menu class="list" url="www.some.site/widget/system-menu-widget/-menuRequest/">
        <template is="dom-repeat" items='{{data}}'>
            <li>{{item.label}}<li>
        </template>
    </system-menu>`

For some reason, the {{data}} isnt binding anything. 由于某些原因, {{data}}绑定任何东西。 It just shows {{data}} in the chrome inspect element console 它仅在Chrome检查元素控制台中显示{{data}}

要访问data从加载system-menu的外部system-menu元素,您需要将其添加为一个属性:

<system-menu class="list" url="www.some.site/widget/system-menu-widget/-menuRequest/" data="{{data}}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM