我试图绑定自定义元素中的一些数据,但无济于事。我有一个系统menu.html有我的自定义元素:聚合物1.0数据绑定不按预期方式工作
系统menu.html
<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>
<template is="dom-repeat" items="{{data}}">
<li>{{item.name}}</li>
</template>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'system-menu',
behaviors: [
Polymer.IronMenubarBehavior
],
ready: function() {
console.log(this.data);
}
});
})();
</script>
这是我如何使用它(请注意,我已经做了所有进口其他项)
<link rel="import" href="/themes/_components/custom_components/system-menu/system-menu.html">
<style>
.list {
display: inline-block;
padding: 8px 0;
}
.list li {
display: block;
padding: 8px;
}
.list li[disabled] {
color: #ccc;
}
</style>
<system-menu class="list flex horizontal end-justified layout" data="{{data}}"></system-menu>
此外,{{数据}}在此文件JSON编码从PHP数据。这是
{"login":{"url":"/login","parent_id":"0"},"register":{"url":"/register","parent_id":"0"}}
我的问题是,我该如何访问和我系统menu.html模块使用JSON数据数据?
目前我得到这些错误:
[dom-repeat::dom-repeat]: expected array for
items
, found {Uncaught TypeError: Cannot read property 'getKey' of undefined
@ user241584是完全正确的 - 你的'{{数据}}'是一个对象,而不是一个数组。然而这只是你的代码中的一个问题。你在输出中究竟期待什么? – zerodevx
@zerodevx我只需要一个在'system-menu.html'中使用的例子,无论哪种方式 –
它创建一个列表项目,它转换为一个菜单 –