2011-11-21 103 views
1

我是sencha touch應用程序開發的新手。我試圖從遠程服務器上加載一些數據到列表中。我創建瞭如下的商店:在sencha touch中註冊JSONm商店

Ext.regStore('customers',{ 

model : 'customer', 
sorters : 'firstName', 
storeId : 'customers', 
data : [{ 
    id : 100, 
    firstName : 'aaa' 
}, { 
    id : 101, 
    firstName : 'sss' 
}, { 
    id : 102, 
    firstName : 'rrrr' 
}] 

});

現在我需要修改這個店來檢索外部server.Follwoing數據是我使用現在的代碼

var customers = new Ext.data.JsonStore({ 
     model : 'customer', 

      proxy : { 
      type : 'ajax', 
      url:'http:sample.com', 

      reader : { 
       type : 'json', 
       root : '', 
      },        
     }, 

     listeners : { 

      datachanged : function() { 

       customers.each(function(r) { 
        console.log('data in record is:'+ r.get('name')); 
       }); 
      } 
     }, 
    }); 

現在我的疑問是,如何註冊這個JSON店像inital代碼從另一個視圖控制器文件訪問商店。

在此先感謝

回答

0

您可以使用屬性:

STOREID = 「NameOfStoryID」

填寫你的店就可以了,以後在你的代碼後,使用此STOREID訪問商店(獲取數據,更新等)。

例子:

var schouwLijstStore = new Ext.data.Store({ 

     model: "schouwLijst", 
     storeId: "myStore", 
     proxy: { 
      type: 'ajax', 
      url: 'php/json.php?t=list', 
      reader: { 
       type: 'json', 
       root: 'list' 
      }, 
     },  
     autoLoad: true, 
     listeners: { 
      load: function() { 

           // Do things on load (sync to offline store for example) 

      } 

     } 

    }); 

我們稍後訪問您的商店的代碼,你可以用你的STOREID。例如加載它:

//加載 myStore.load();

//添加項目 myStore.add({id:* ,value:*});

相關問題