0

我正在尝试使用一个可以在事件处理程序完成后返回对象的 Deferred.when 语句。我的代码如下所示。有人可以指导我如何使它工作吗?我正在使用dojo 1.7。

define(["dojo/_base/declare","dojo/_base/lang", "dojo/_base/xhr",
    "dojo/_base/json","dojo/_base/Deferred","dijit/registry","dojo/_base/connect",
    "dojo/query","dojo/on","dojo/dom-attr","dojo/dom","dojo/has","dojo/json","dojo/dom-style"],
    function(declare,lang,xhr,json,Deferred,registry,connect,$,on,attr,dom,has,json,domStyle)
    {

        declare("model.Item", [], 
        {
            deferred:null,
            item:null,
Load: function(){
               this.deferred = new Deferred();

               var overlay = registry.byId("readFromStore");
                   overlay.show();
                   Deferred.when(connect.connect(registry.byId("storeReadOK"),"onClick",this,this.loadFromStorage), (return (this.deferred)));
                  // I want modification for the above line.
                }

loadFromStorage:function()
                {
            // Do something here
               this.deferred.callback(this.item);

           }
     return model.Item;
        }
    );

我还尝试了下面的 Load 函数代码,但它也不起作用。

    Load: function(){

     this.deferred = new Deferred();

              connect.connect(registry.byId("storeReadOK"),"onClick",this,this.loadFromStorage);
                var overlay = registry.byId("readFromStore");
                    overlay.show();
                        //  Deferred.when(connect.connect(registry.byId("storeReadOK"),"onClick",this,this.loadFromStorage),(overlay.hide()));

                return this.deferred;
     }
4

1 回答 1

0

下面的代码工作正常,由于我的代码中的一些其他错误,我遇到了问题,我已经纠正了这些错误,现在工作正常。感谢所有试图帮助我的人。

   Load: function(){

 this.deferred = new Deferred();

          connect.connect(registry.byId("storeReadOK"),"onClick",this,this.loadFromStorage);
            var overlay = registry.byId("readFromStore");
                overlay.show();
               return this.deferred;
 }
于 2013-09-17T10:58:42.127 回答