Dojo AMD: Can't call a function inside a require

后端 未结 3 364
夕颜
夕颜 2020-12-31 08:49

I am really a newbie to dojo but as i started developing a new application with dojo version 1.7.2 i also wanted to use the new AMD syntax for functions. Unfortunately i don

3条回答
  •  执笔经年
    2020-12-31 09:26

    Try this:

    require([...], function() {
        var myFunctions = dojo.getObject('myFunctions', true);
        myFunctions.createNewRow = function(...) {
            ...
        };
    });
    

    You can now call your functions from anywhere by using

    myFunctions.createNewRow();
    

    If you don't want 'myFunctions', you could do

    require([...], function() {
        var createNewRow = function(...) {};
    
        dojo.setObject('createNewRow', createNewRow);
    });
    

提交回复
热议问题