json中的聚合子菜单和项
我试图从json生成聚合子菜单和项。代码只是嵌套的子菜单和项目模板:json中的聚合子菜单和项,json,polymer,Json,Polymer,我试图从json生成聚合子菜单和项。代码只是嵌套的子菜单和项目模板: <polymer-element name="years-submenu" noscript> <template> <core-ajax auto url="../json/years and offices.json" response="{{items}}" handleAs="json"></core-ajax> <template repeat
<polymer-element name="years-submenu" noscript>
<template>
<core-ajax auto url="../json/years and offices.json" response="{{items}}" handleAs="json"></core-ajax>
<template repeat="{{item in items}}">
<core-submenu icon="visibility" label="{{item.year}}">
<template repeat="{{office in item.offices}}">
<core-item id="{{item.year}} {{office}}" label="{{item.year}} {{office}}"></core-item>
</template>
</core-submenu>
</template>
</template>
</polymer-element>
这会显示年份,但不会显示办公室名称。奇怪的是,如果我检查chrome中的元素,我可以看到它正在为id而不是标签插入{item.year}和{{office}。我尝试过各种显式绑定的方法,但都没有用;当然,我可能尝试了错误的方法。任何关于如何使这项工作的想法都将不胜感激 结果是,如果我将包装子菜单代码放在自定义元素中(而不是从包装自定义元素的主页调用子菜单),它就会工作 因此,按以下方式调用问题中发布的元素不起作用:
<core-menu selected="{{selected}}" valueattr="id" theme="core-light-theme">
<years-submenu></years-submenu>
</core-menu>
但从主页调用以下命令确实有效:
<polymer-element name="years-menu" noscript>
<template>
<core-menu selected="{{selected}}" valueattr="id" theme="core-light-theme">
<core-ajax auto url="../json/years and offices.json" response="{{items}}" handleAs="json"></core-ajax>
<template repeat="{{item in items}}">
<core-submenu icon="visibility" label="{{item.year}}">
<template repeat="{{office in item.offices}}">
<core-item id="{{item.year}} {{office}}" label="{{item.year}} {{office}}"></core-item>
</template>
</core-submenu>
</template>
</core-menu>
</template>
</polymer-element>
我不完全理解为什么,但问题解决了。我创建了一个聚合元素来从JSON创建菜单。它还有一些其他很酷的功能,我将继续增强它 这不完全符合你的问题,但请检查一下 如果您有任何问题/想法,请创建github问题/请求
它对我有效:。你正在导入你正在使用的所有元素吗?@ebidel我正在导入它们,尽管毫无疑问我在做其他错误的事情。你知道,在查看你的jsbin代码时,看起来子菜单的标签没有显示。在我的代码中,问题恰恰相反——项目没有显示。你能解释为什么吗子菜单标签没有显示在您的jsbin代码中?这可能有助于我理解。@ebidel,或者至少我认为我是。我正在从我的bower\u组件的core菜单文件夹中的core-submenu.html导入core子菜单。是否正确?(我尝试过bower单独安装core子菜单,但无法做到。)
<polymer-element name="years-menu" noscript>
<template>
<core-menu selected="{{selected}}" valueattr="id" theme="core-light-theme">
<core-ajax auto url="../json/years and offices.json" response="{{items}}" handleAs="json"></core-ajax>
<template repeat="{{item in items}}">
<core-submenu icon="visibility" label="{{item.year}}">
<template repeat="{{office in item.offices}}">
<core-item id="{{item.year}} {{office}}" label="{{item.year}} {{office}}"></core-item>
</template>
</core-submenu>
</template>
</core-menu>
</template>
</polymer-element>