Polymer告诉我"Uncaught SyntaxError:Unexpected token"

Oli*_*rPT 3 javascript custom-component polymer

在下面的Polymer自定义组件中,当调用函数'deleteState'时(所以当我点击"删除"纸质项目时)我总是得到"Uncaught SyntaxError:Unexpected token("来自Chrome.在Firefox上,我得到了"SyntaxError" :function语句在控制台中需要名称"错误.

<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>
Run Code Online (Sandbox Code Playgroud)

在查看了文档和大量示例后,我仍然没有看到我做错了什么...

Dir*_*orf 5

paper-item你想要聚合物事件处理程序

on-click="{{deleteState}}"
Run Code Online (Sandbox Code Playgroud)

而不是普通的onclickDOM处理程序.如果使用onclick字符串"{{deleteState}}"被评估为JavaScript代码,则会导致上述错误.

如果使用on-click,Polymer会对此字符串求值,并将该deleteState()函数绑定为单击处理程序.