简体   繁体   English

如何使用dom-repeat在Polymer 1.0中创建动态菜单

[英]How to create a dynamic menu in Polymer 1.0 using dom-repeat

First of all, sorry for my english, this is my first question here. 首先,对不起我的英语,这是我在这里的第一个问题。 I have a problem creating a dynamic menu with dom-repeat, here is my template: 我在使用dom-repeat创建动态菜单时遇到问题,这是我的模板:

<paper-menu class="list" on-iron-select="onMenuSelect" id="mainMenu" >
   <template is="dom-repeat" items="{{menu.Options}}" as="menu" id="iron_pages_app">
       <paper-item on-tap="funcion" data="{{menu}}"><iron-icon icon="{{menu.Icon}}"></iron-icon><span>{{menu.Name}}</span></paper-item>
       <template is="dom-repeat" items="{{menu.Options}}" as="sub" id="iron_pages_app_2">
           <paper-item on-tap="funcion_dos" class="olakease"><span style="padding-left: 3em">{{sub.Name}}</span></paper-item>
                <template is="dom-repeat" items="{{sub.Options}}" as="subDos">
                    <paper-item on-tap="funcion_tres"><span style="padding-left: 6em">{{subDos.Name}}</span></paper-item>
                </template>
        </template>
    </template>
</paper-menu>

As you can see this code try to fix the problem that polymer 1.0 has not submenu. 如您所见,此代码尝试解决聚合物1.0没有子菜单的问题。 The render of data works fine, so my really question is how to get the information of my sub-elements, because if I use: 数据呈现工作正常,所以我真正的问题是如何获取子元素的信息,因为如果使用:

var item = this.$.iron_pages_app.itemForElement(e.target);

works fine, but if i try to do the same with "sub-menu elements" don't show nothing. 工作正常,但如果我尝试对“子菜单元素”执行相同操作,则什么也不显示。 I have tried: 我努力了:

var item = this.$$("#iron_pages_app_2").itemForElement(e.target);
var item = Polymer.dom(this.root).querySelector("#iron_pages_app");

Any suggestion? 有什么建议吗? Thanks 谢谢

Edit 编辑

Finally I can get the information of each submenus, but I think the way I did is not right one, here is the code: 最后,我可以获得每个子菜单的信息,但是我认为我做的方法不正确,这里是代码:

var item = e.model.__data__.sub;

where "sub" is the alias of my second dom-repeat, anyone can help me with a better solution? “ sub”是我第二次dom-repeat的别名,有人可以帮助我提供更好的解决方案吗? Thanks again. 再次感谢。

Edit 编辑

var menu = event.model.menu;
var sub = event.model.sub;
var subDos = event.model.subDos;

This works fine, but on third level cant access to information of sub or menu, just doesnt appear. 这可以正常工作,但是在第三级上无法访问子菜单或菜单的信息,只是没有出现。

In "funcion" I need only information about this level. 在“功能”中,我仅需要有关此级别的信息。

In "funcion_dos" I need information about this level and first level. 在“ funcion_dos”中,我需要有关此级别和第一级别的信息。

In "funcion_tres" I need information about two previous level. 在“ funcion_tres”中,我需要有关前两个级别的信息。

I hope you can understand me, sorry for my english again. 希望您能理解我,再次抱歉我的英语。

如果您尝试访问点击事件处理程序中的项目,则应该可以使用event.model.item尽管使用了as属性为项目属性分配了不同的名称,所以您将使用这些名称而不是.item,例如event.model.subDos

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

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