简体   繁体   English

聚合物函数调用,但无结果

[英]Polymer function call but no result

Old Question: How can I call a Polymer Function? 旧问题:如何调用聚合物功能? (check edits, I don't want to cram code in here) (检查编辑,我不想在这里填充代码)

Rewrite: 改写:

I have a <core-scaffold> that I want to call the togglePanel() function. 我有一个<core-scaffold> ,我想调用togglePanel()函数。 (This sits in project_root/index.html .) I do this using: (这位于project_root/index.html 。)我使用以下方法执行此操作:

<core-icon-button onclick="document.querySelector('core-scaffold').togglePanel();"
icon="drawer></core-icon-button>

In Chrome's Inspector, I can see this causes no errors, but it doesn't do anything on-screen. 在Chrome浏览器的Inspector中,我可以看到这不会导致任何错误,但是它在屏幕上没有任何作用。 My code calls this function in project_root/bower_components/core-scaffold/core-scaffold.html : 我的代码在project_root/bower_components/core-scaffold/core-scaffold.html调用此函数:

togglePanel: function() {
  this.$.drawerPanel.togglePanel();
}

Which in turn calls this function in project_root/bower_components/core-drawer-panel/core-drawer-panel.html : 依次在project_root/bower_components/core-drawer-panel/core-drawer-panel.html调用此函数:

togglePanel: function() {
  this.selected = this.selected === 'main' ? 'drawer' : 'main';
}

I am either to naive and unexperienced to see the problem, or have a terrible complex bug. 我要么天真,没有经验,要么看到这个问题,或者遇到了一个可怕的复杂错误。 Any help would be appreciated! 任何帮助,将不胜感激!

您可以使用查询选择器直接获取元素,并像其他HTML页面一样在onclick上调用其方法

<button onclick="document.querySelector('core-drawer-panel').togglePanel();">toggle drawer</button>

I ran into the problem as well. 我也遇到了这个问题。 The issue is that the closeDrawer(), openDrawer(), and togglePanel() are only usable when size of your screen is less than the value of responsiveWidth. 问题在于,仅当屏幕尺寸小于响应宽度的值时,closeDrawer(),openDrawer()和togglePanel()才可用。

I think the logic is that if you have the screen real estate you would always want to show the drawer. 我认为逻辑是,如果您拥有屏幕空间,则总是想显示抽屉。 Of course this could be tweaked by extending core-drawer-panel and making a custom core-scaffold implementation. 当然,可以通过扩展核心抽屉面板并进行自定义核心支架实现来进行调整。

Change the published attribute in core-drawer-panel.html forceNarrow=true 在core-drawer-panel.html forceNarrow=true更改发布的属性
See @ Call function on polymer navigation drawer panel 请参阅聚合物导航抽屉面板上的 @ 调用功能

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

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