单击事件不在聚合物纸图标按钮中触发

时间:2015-06-17 15:31:11

标签: javascript polymer

我定义了以下页面

<!DOCTYPE html>
<html>
<head>
    <title>Practice List</title>
    <link rel="import" href="elements/elements.html" />
    <link rel="stylesheet" type="text/css" href="Styles/styles.css" />
    <!-- google fonts definitions -->
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
    <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
</head>
<body unresolved class="fullbleed layout vertical">
    <dom-module id="app">
        <template>
            <paper-drawer-panel>
                <paper-header-panel main mode="waterfall-tall">
                    <paper-toolbar id="mainToolbar">
                        <paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
                        <span class="flex"></span>
                        <paper-icon-button icon="search" on-tap="srchandler"></paper-icon-button>
                        <input type="text" id="searchText" style="width:200px; background:#3180ed;line-height:20px;border:solid 1px #4d90eb; border-radius:6px; padding:3px;color:#fff;" />
                        <div class="middle paper-font-display2 app-name ident">Practice List</div>
                    </paper-toolbar>
                </paper-header-panel>
            </paper-drawer-panel>
        </template>
        <script>
            Polymer({
                is: "app",
                ready: function () {
                    alert('Ready!!!!');
                },
                srchandler: function () {
                    alert('Search clicked');
                }
            });
        </script>
    </dom-module>
</body>
</html>

为了完整性,这里是elements.html文件

<!-- Iron -->
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">

<!-- Paper Elements -->
<link rel="import" href="../bower_components/paper-drawer-panel/paper-drawer-panel.html">
<link rel="import" href="../bower-components/paper-header-panel/paper-header-panel.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-styles/paper-styles.html">
<link rel="import" href="../bower_components/paper-toolbar/paper-toolbar.html">

我正在转向Polymer 1.0并刚刚创建了上面的页面。 '脚本处理程序调用'警告正在显示,但ready回调未触发,当我点击搜索按钮时,searchhandler函数未被调用。

任何人都可以告诉我哪里出错了吗?

1 个答案:

答案 0 :(得分:6)

有关迁移指南,请参阅here。如果您的活动没有开始,请参阅here

  

curly方括号({{}})不用于模板中的声明性事件处理程序。

您的代码应为:

<paper-icon-button icon="search" on-tap="srchandler"></paper-icon-button>

您的元素注册现在也需要更改。见here

<body unresolved class="fullbleed layout vertical">
    <dom-module id="my-app">
        <template>
        <!-- your template here -->
            <paper-drawer-panel>
                <paper-header-panel main mode="waterfall-tall">
                    <paper-toolbar id="mainToolbar">
                        <paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
                        <span class="flex"></span>
                        <paper-icon-button icon="search" on-tap="srchandler"></paper-icon-button>
                        <input type="text" id="searchText" style="width:0px;visibility:hidden;" />
                        <div class="middle paper-font-display2 app-name ident">Practice List</div>
                    </paper-toolbar>
                </paper-header-panel>
            </paper-drawer-panel>
        </template>
        <script>
            Polymer({
                is: "my-app",
                ready: function () {
                    alert('Ready!!!!');
                },
                srchandler: function () {
                    alert('Search clicked');
                }
            });
        </script>
    </dom-module>

    <my-app></my-app>
</body>