首先,我很喜欢聚合物。我不擅长JavaScript,并且我没有完全理解所有正在发生的影子DOM内容。但我认为Polymer正在为像我这样的人开发(非全职编码人员需要快速构建网站并通过将简单的部分组合在一起编程)。这很有趣,而且一旦我明白它的内容是如何运作的,那真的很可爱。聚合物子菜单/页面导航需要脚本吗?
我最近尝试构建网站/应用涉及到很多连接到核心页面的菜单和子菜单项。我喜欢这样的想法,即我可以在核心页面中将菜单项ID与div id连接起来并完成这项工作。而当我用菜单项和手工编码的ID来完成时,它完美地工作。但是,当我添加核心子菜单和模板重复生成的项目和页面与匹配的ID,出于某种原因,可能是明显的其他人,它不。
我的问题:子菜单/页面是否需要脚本,或者我的聚合物标签是否有问题?如果需要编写脚本,我很乐意为初学者提供一些资源指针。我看了一下spa.html演示,但它不包含子菜单。有小费吗?
现在,我的代码的核心是这样的:http://jsbin.com/xuzezelumeje/1/edit
<script src="http://www.polymer-project.org/platform.js"></script>
<link rel="import" href="http://www.polymer-project.org/components/core-scaffold/core-scaffold.html">
<link rel="import" href="http://www.polymer-project.org/components/core-header-panel/core-header-panel.html">
<link rel="import" href="http://www.polymer-project.org/components/core-menu/core-menu.html">
<link rel="import" href="http://www.polymer-project.org/components/core-menu/core-submenu.html">
<link rel="import" href="http://www.polymer-project.org/components/core-item/core-item.html">
<link rel="import" href="http://www.polymer-project.org/components/core-pages/core-pages.html">
<polymer-element name="my-app">
<template>
<core-scaffold>
<core-header-panel navigation flex mode="seamed">
<core-toolbar></core-toolbar>
<core-menu selected="{{selected}}" valueattr="id" theme="core-light-theme">
<template repeat="{{item in items}}">
<core-submenu icon="visibility" label="{{item.year}}">
<template repeat="{{office in item.offices}}">
<core-item id="{{office}} {{item.year}}" label="{{office}}"></core-item>
</template>
</core-submenu>
</template>
</core-menu>
</core-header-panel>
<div tool>DC Campaign Finance Watch</div>
<core-pages selected="{{selected}}" valueattr="id">
<template repeat="{{item in items}}">
<template repeat="{{office in item.offices}}">
<div id="{{office}} {{item.year}}">{{item.year}} {{office}}</div>
</template>
</template>
</core-pages>
</template>
<script>
Polymer({
ready: function() {
this.items = [
{
"offices": [
"Mayor",
"Council Chairman",
"Council At-Large",
"etc"
],
"year": "2014"
},
{
"offices": [
"Council At-Large"
],
"year": "2013"
},
{
"offices": [
"Council Chairman",
"Council At-Large",
"etc"
],
"year": "2012"
},
{
"offices": [
"Council At-Large",
"School Board Ward 4",
"School Board Ward 8"
],
"year": "2011"
},
{
"offices": [
"Mayor",
"Council Chairman",
"etc"
],
"year": "2010"
}
];
}
});
</script>
</polymer-element>
<my-app></my-app>
哇 - 感谢你全面的回答和功能码!现在我可以看到为什么过滤器在其他人的代码中比我的更常见。我也看到了on-core-select是如何工作的,这非常好。我担心我必须熟练掌握熨斗的所有细节,但是您提供的js是令人放心的简单。非常感谢! – Don 2014-10-03 00:17:45