0

下面是我从将“this”绑定到 javascript 中的单击事件时遇到的错误。js 的格式是 Jaml/Mooml,有些人可能不熟悉,但我向你保证语法是正确的。我一直以相同的方式将“this”绑定到许多事件,这是我第一次看到这个错误,所以我希望一些 mootools、jaml 或 javascript 专家能够从下面的错误和代码中得出解决方案。

Uncaught TypeError: Object [object Object] has no method 'get'
Mooml.engine.tags.div.Mooml.engine.tags.div.events.click:relay(a)
bubbleUpmootools-core-1.4.1.js:3948
delegation.addEvent.delegatormootools-core-1.4.1.js:4078
defn

这里是果酱...

    'main': new Mooml.Template(null, function(data) {
        div({'class': 'lists container'},
            div({
                'class': 'sources',
                'events': {
                    'click:relay(a)': function(event) {
                        event.preventDefault();

                        new Resource({
                            'url': this.get('href'),
                            'method': 'FRIENDS',
                            'query' : {
                                'source': this.dataset.source
                            },

                            'onSuccess': function(response) {
                                console.log(response);
                                //this.renderTemplate('friends', response.mv, this);

                            }.bind(this),

                            'onFailure': this.onFailure

                        }).send();

                    }.bind(this)
                }
4

1 回答 1

4

添加var self = this; 在您的代码之前,然后在回调函数中使用self而不是。this

也看看http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/http://javascriptweblog.wordpress.com/2010/08/30/understanding- javascripts-this/了解更多关于如何this工作的信息。

于 2011-12-27T16:20:33.927 回答