Question

I am writing on a JavaScript application which uses the dojo Toolkit. I have made a folder in the dojo folder called "md" (My Dojo). There are 2 .js files in there myownclass.js and myComboBox.js . myownclass.js is for retrieving Informations from a SQLite Database by making a dojo Request (works) to sqlaccess.php . firebug is telling me that the request is correct. But the function does not want to go to the function prepare_str(str) and push the string to the Array data : [].

data : [],

constructor : function( ){
        this.getdata();
    },

    //gets Data
getdata : function(){
    xhr("sqlaccess.php?order=0").then(function(text){
                                                                                    this.prepare_str(text.toString().split(";"));});
        return this.data;
    },
    //push Data to Array    
prepare_str : function(str){
    alert(str);
    for(var index = 0; index < str.length; index++)
    {
        data.push({name:str[index], id: index});
    }
    //get
    },

the full code you can see in: http://pastebin.com/aKUrLmcH

and the other error is in myComboBox.js where it tells me that new ComboBox() is not a constructor

MyMemory : null,
        comboBox : null,
        //keyhandle : null,

        oldval : "",
        constructor: function(){
            this.MyMemory = new myownclass();
            var stateStore = new Memory({data : this.MyMemory.data});
            comboBox = new ComboBox({
                            id: "stateSelect",
                            name: "state",
                            value: "",
                            store: stateStore,
                        searchAttr: "name"
                        }, "stateSelect");
                var handle = on(dom.byId("stateSelect"),"keyup", this.keyupfoo);        
            },

the full code is readable here: http://pastebin.com/hi8nkymf

Can anyone see the error I am making?

Thanks for help

Was it helpful?

Solution

Your first problem, with the prepare_str() function not being called is due to a scoping issue. When you rely on a callback, then this will no longer refer to your class. To solve that you could use the hitch() method of the dojo/_base/lang module, for example:

xhr("sqlaccess.php?order=0").then(lang.hitch(this, function(text){
    this.prepare_str(text.toString().split(";"));
}));

This makes sure that the callback of the xhr() function will use the current object as scope and so this will refer to your class (which contains the prepare_str() function).


I'm not sure why your combobox is not working though. Make sure the module is being loaded correctly and also note that in your constructor of your myComboBox you should not forget to use the this.

this.comboBox = new ComboBox({
    id: "stateSelect",
    name: "state",
    value: "",
    store: stateStore,
    searchAttr: "name"
}, "stateSelect");

If you want further help with your constructor problem, you should try to make a screenshot of the console where your error is or at least give the full stacktrace of the error (I'm assuming it's located at the new ComboBox() statement, but I want to be sure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top