2013-08-29 27 views

回答

2

有Ext.data.Store看看http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.Store

你不能使用你的數據庫直接,你必須實現前端和後端(服務器端或也與此層客戶端後端,如HTML5 Webstorage)。從鏈接煎茶文檔

客戶端例如:

// Set up a model to use in our Store 
Ext.define("User", { 
    extend: "Ext.data.Model", 
    config: { 
     fields: [ 
      {name: "firstName", type: "string"}, 
      {name: "lastName", type: "string"}, 
      {name: "age",  type: "int"}, 
      {name: "eyeColor", type: "string"} 
     ] 
    } 
}); 

var myStore = Ext.create("Ext.data.Store", { 
    model: "User", 
    proxy: { 
     type: "ajax", 
     url : "/users.json", 
     reader: { 
      type: "json", 
      rootProperty: "users" 
     } 
    }, 
    autoLoad: true 
}); 

Ext.create("Ext.List", { 
    fullscreen: true, 
    store: myStore, 
    itemTpl: "{lastName}, {firstName} ({age})" 
}); 

Serverside集團取決於您的環境。如果您使用基於服務器的後端,則以您選擇的編程語言實現REST API。

爲了在本地設備/瀏覽器上存儲數據,您必須實現LocalStorage代理。 http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.proxy.LocalStorage

+0

我想存儲數據,當應用程序打開回來然後想要使用該數據。 –

+0

所以你必須使用上面提到的Ext.data.Store和LocalStorage代理(http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.proxy.LocalStorage),它允許您將數據存儲在客戶端的瀏覽器中,而不需要服務器後端。 –

相關問題