使用dojo lang.hitch获取方法未定义错误

时间:2013-10-04 17:06:47

标签: dojo amd

我是dojo的新手,我正在尝试使用lang.hitch方法来处理我的回调,但是在使用它时我一直收到“未捕获的参考错误:未定义错误”。我确定我做错了什么 - 我只是不确定它是什么。 this引用我在initializeLocators函数中新创建的对象,在我逐步执行代码时进行了验证。 showResults方法的candidate参数从事件处理闭包返回。谢谢你的帮助。

我的课程:

define(["dojo/_base/declare", ..., "dojo/_base/lang", "dojo/on", "dojo/dom", ...], 
function(declare, ..., lang, ...){
    var SDCLocateClass = declare(null, {
        ...,
        constructor: function() {
            this.initializeLocators();
        },
        initializeLocators: function() {
            this.addressNode = dom.byId("resultsDiv");


            //set up the address locator functionality
            this.locator = new Locator("http://...");
            this.locator.on("address-to-locations-complete", lang.hitch(this, showResults));
        },
        showResults: function(candidates) {
            ...
        },
    });
    return SDCLocateClass;
});

1 个答案:

答案 0 :(得分:2)

showResults是未定义的变量。使用this.showResults或使用字符串"showResults"

this.locator.on("address-to-locations-complete", 
    lang.hitch(this, this.showResults));
相关问题