gpt4 book ai didi

javascript - 单击工具栏中的纸张选项卡时如何取消核心工具栏点击事件

转载 作者:行者123 更新时间:2023-12-02 16:59:49 24 4
gpt4 key购买 nike

当我在瀑布高模式下单击纸张选项卡上方的空间时,我想触发主页功能。

    <core-header-panel mode="waterfall-tall">

<core-toolbar class="animate" id="core_bar" on-tap={{home}}>

<paper-tabs selected="0" self-end id="paper_tabs">
<paper-tab>0</paper-tab>
<paper-tab>1</paper-tab>
<paper-tab>2</paper-tab>
<paper-tab>3</paper-tab>
</paper-tabs>

</core-toolbar>

<core-animated-pages transitions="slide-from-right" selected="{{ $.paper_tabs.selected }}" id="core_pages">

<section></section>
<section></section>
<section></section>
<section></section>
<section>My home</section>

</core-animated-pages>

</core-header-panel>

这会触发主页功能,但是当我单击纸质选项卡时,主页功能也会被调用。点击纸质标签时如何取消主页功能?

<script>
Polymer('my-pages', {
home:function(){
this.$.paper_tabs.selected=4
}
});
</script>

最佳答案

你可以这样做:

home: function(e) {
// make sure this tap was on the core-toolbar itself
if (e.target.localName === 'core-toolbar') {
this.$.paper_tabs.selected = 4;
}
}

但是,以这种方式引用 $.paper_tabs 并不是一个好的做法。相反,确定您的 my-pages 具有 activePage 属性,并将 UI 元素绑定(bind)到该属性。这样,您的逻辑和模板 UI 就会松散耦合

...
<template>
...
<paper-tabs selected="{{activePage}}" self-end>
...
<core-animated-pages selected="{{activePage}}" transitions="slide-from-right">
...
</template>
<script>
Polymer({
activePage: 0,
home: function(e) {
if (e.target.localName === 'core-toolbar') {
this.activePage = 4;
}
}
});
</script>

作为一般规则,请尽量避免在模板中使用 id。这意味着您的元素是数据驱动的,您可以重新设计 UI,而无需触及脚本。

关于javascript - 单击工具栏中的纸张选项卡时如何取消核心工具栏点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com