有没有办法用数据预先填充iron-menu元素而不是创建新的自定义元素,还是可以扩展?使用聚合物1.0。 我创建了自己的元素并满足了上述要求,但创建一个几乎与现有元素完全相同的元素是否真的很明智?考虑一下:
这是铁菜单元素代码:
<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">
<style>
.content ::content > .iron-selected {
color: red;
}
.content ::content > * {
display: inline-block;
}
</style>
<template>
<div class="content">
<content></content>
</div>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'system-menu',
behaviors: [
Polymer.IronMenubarBehavior
]
});
})();
</script>
我想保留铁菜单行为。使用它时,我不能做这样的事情:
<system-menu class="list">
<template is="dom-repeat" items="{data}">
<li>{{item.label}}</li>
</template>
</system-menu>
我从铁菜单行为示例中获取此代码
答案 0 :(得分:0)
I found the answer to this, looks like I wasnt escaping {{data}}
My array was something like this
[{"label":"login","url":"\/login","parent_id":"0"},{"label":"register","url":"\/register","parent_id":"0"}]
And I was sending it using items="{{data}}"
, thus the end result would be:
items="{{[{"label":"login","url":"\/login","parent_id":"0"},{"label":"register","url":"\/register","parent_id":"0"}]
}}"
The array was php generated so I wasnt aware of the ""
quotes. I found that changing items to items={{data}}
solved my issue.