Polymer give me "Uncaught SyntaxError: Unexpected token ("

Polymer give me "Uncaught SyntaxError: Unexpected token ("

在下面的 Polymer 自定义组件中,当函数 'deleteState' 被调用时(所以当我点击 "delete" paper-item 时)我总是从 [=21 得到 "Uncaught SyntaxError: Unexpected token (" =]. 在 Firefox 上,我在控制台中收到 "SyntaxError: function statement requires a name" 错误。

<polymer-element name="tw-state" attributes="stateId">
<template>
    <style>
       ...
    </style>

    <paper-shadow z="1">
        <div layout vertical>
            <div class="state-header" layout horizontal center-justified>
                <div flex style="margin: 10px">
                    <content select="h3"></content>
                </div>                    
                <paper-menu-button>
                    <paper-icon-button icon="menu" noink></paper-icon-button>
                    <paper-dropdown class="dropdown">
                        <core-menu class="menu">
                            <paper-item>Settings</paper-item>
                            <paper-item onclick="{{deleteState}}">Delete</paper-item>
                        </core-menu>
                    </paper-dropdown>
                </paper-menu-button>
            </div>
            <div class="state-body" layout vertical start>
                <content></content>
            </div>
            <div class="state-footer"  layout horizontal center-justified>
                <paper-input-decorator label="New task" flex>
                    <input is="core-input">
                </paper-input-decorator>
                <paper-button noink="" role="button" tabindex="0">
                    <core-icon icon="add" aria-label="add" role="img"></core-icon>
                </paper-button>
            </div>
        </div>
    </paper-shadow>

</template>
<script>
    Polymer({

        deleteState: function() {
            console.log("Fire event delete-state");
            this.fire('delete-state', {id: 'this.stateId'});
        }

    });
</script>

在查看了文档和大量示例之后,我仍然看不出我哪里做错了...

在你的 paper-item 你想要 polymer event handler

on-click="{{deleteState}}"

而不是正常的 onclick DOM 处理程序。如果您使用 onclick 字符串“{{deleteState}}”被评估为 JavaScript 代码,导致上述错误。

如果您使用 on-click,Polymer 会评估此字符串并将 deleteState() 函数绑定为点击处理程序。