javascript - 我想在服务器响应之间加载本地存储(使 javascript 代码同步)

标签 javascript callback synchronization sencha-touch-2

I have view page where am trying to display all organizations,which is obtained by a server call..In order to feel the application responsive , in between the server response I want to load all local store items.. But server call is always executing first.. The code I mentioned bellow..

initialize: function() 
{
    var me = this,
    st = Ext.create("Ext.data.Store", {
         fields : [ {......................}]});
    me.callParent(arguments);  

    me.setStore(st);

    me.on({
        show  : me.onShow,              
        scope: me
        });   

},

onShow:function()
{
      var me = this;
      Ext.create('Ext.util.DelayedTask', 

      //call back function ,purpose : delayed exicution

          function () {
          me.DelShow(function(){
         _syncMgr.getOrgGroup(-1,0,5); // servercall
          });
          }).delay(500);
},  

DelShow: function(callback)
{

            orgStore = Ext.getStore('Organizations'),
            orgStore.load(function(records)
                {
                    var i=0,len = records.length,
                    for(;i<len;i++)
                    {
                        organization = records[i];
                        regId = organization.get('rg_id');
                        resStr = organization.Resources();                      
                        resStr.load({callback:function(resorces)
                         {
                            var i = 0,rlen =resorces.length,
                            obj = {},
                            obj.rg_id = str.boundTo.get('rg_id');

                        }
                           orgViStr.add([obj]);


                       });
                     }
                });
    me.lodorg(callback);

    },


lodorg:function(callback)

{
 callback();
 console.log("I don't know why this call back works first....");
 console.log("plz help me to work last....");     

}

最佳答案

从本地存储加载数据后调用回调方法。

关于javascript - 我想在服务器响应之间加载本地存储(使 javascript 代码同步),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22558720/

相关文章:

javascript - 为什么我的 Raphael 笔画不具有相同的宽度或不透明度?

c# - 限制并发调用的最佳实践

c - C 中的同步对象及其与数据结构结构的关联

javascript - 从单个响应元素获取多个高度值

javascript - 无法选择单选按钮

javascript - Jquery选择器下一个元素

javascript - 多次连续调用带有回调的函数会导致回调 hell

Javascript理解回调函数和执行

validation - 单元测试 Symfony 回调

c++ - C++ 中的 Shared_ptr 和内存可见性