2013-03-05 67 views
0

我需要用我的localStorage與localStorage的煎茶觸摸同步模式

這裏得到我的服務器,並同步模型數據是我的代碼

model.js

Ext.define('bluebutton.model.BlueButton.Loyalty', { 
    extend: 'Ext.data.Model', 
    config: { 
     idProperty: 'loyaltyModel', 
     fields: [ 
      { name: 'fullName' }, 
      { name: 'age' }, 

      { name: 'lastvisited' }, 
      { name: 'consumer_bbID' }, 
      { name: 'merchant_bbID' }, 
      { name: 'sessionId' }, 
      { name: 'deviceId' }, 

      { name: 'updatedPoint' }, 
      { name: 'currentPoint' }, 

      { name: 'action' }, 
      { name: 'result' }, 
      { name: 'loyaltyMembership_Id'} 



     ], 

     proxy: { 
      type: 'rest', 
      url: 'http://192.168.251.131:8080/WebCommon/rest/BBWebService/updateLoyaltyCardPoint', 
      reader: 'json', 
      actionMethods: { 
       create: 'POST', 
       read: 'POST', 
       update: 'PUT', 
       destroy: 'DELETE' 
      }, 


         noCache: false, // get rid of the '_dc' url parameter 

//     extraParams: { 
//     userid: "test", 
//     // add as many as you need 
//    }, 


//   timeout:300, 
//   listeners: { 
//    exception: function(proxy, response, operation) { 
//      alert("Connection Problem"); 
//      
//     } 
//    }, 

      reader: { 
       type: 'json', 

      }, 

      writer: { 
       type: 'json', 

      }, 
     } 






    } 

}); 

Store.js

Ext.define('bluebutton.store.BlueButton.LoginLS', { 
    extend: "Ext.data.Store", 
    requires: ['bluebutton.model.BlueButton.Login'], 
    config: { 


     model :'bluebutton.model.BlueButton.Login', 

     proxy: { 
      type: 'localstorage', 
      id: 'loginLS' 
     } 


    } 
}); 

View.js

Ext.define('bluebutton.view.Login', { 
    extend: 'Ext.form.Panel', 
    xtype: 'loginview', 
    id: 'loginview', 
    requires: [ 
     'bluebutton.view.Main', 
     'Ext.field.Password', 
     'bluebutton.store.BlueButton.LoginLS' 
    ], 

    config: { 
     labelWidth: 80, 
     frame: true, 
     title: 'Please Login', 

     items: [ 

         { 
          xtype: 'textfield', 
          id: 'bbID', 
          label: 'User ID', 

         }, 
         { 
          xtype: 'passwordfield', 
          id: 'bbPassword', 
          label: 'Password', 

         }, 
         { 
          xtype: 'button', 
          text: 'Login', 
          id:'btnLogin', 
//       handler: function() { 


//       } 
         }, 

如何我可以同步我的模型的localStorage當我按下登錄按鈕?請指引我做方案

回答

0

您的店鋪是bluebutton.store.BlueButton.LoginLS

嘗試致電:

Ext.getStore('LoginLS').sync();

的過程,對我的作品:
我的商店名稱是例如爲:MyApp.store.settings.Settings
爲了得到這個店我只需撥打var settings = Ext.getStore('Settings');
現在我可以添加,刪除儲存項目,然後同步:settings.sync();

退房貴店是否在app.js定義或沒有。

1

我可能誤解了問題,但你可以一個storeId屬性添加到店,如「blueButtonStore 」,並同步像這樣:

Ext.getStore('blueButtonStore').sync(); 

要加載在本地存儲存在什麼商店,你可以使用

Ext.getStore('blueButtonStore').load(); 

讓我硝酸鉀如果這不是在說你的問題。

+0

我試試Ext.getStore('blueButtonStore')。sync();但得到空值 – user998405 2013-03-05 09:03:37

+1

@Sergio普拉多感謝加載()的解釋。 – 2013-04-10 10:47:34

2

設置你的模型對象,髒標誌,當你創建:

var loyalty = Ext.create('bluebutton.model.BlueButton.Loyalty', { ... }); 
    loyalty.setDirty(true); // <== missing step! 
    var store = Ext.getStore('blueButtonStore'); 
    store.add(loyalty); 
    store.sync(); 

您還可以設置自動同步:真實和自動加載:真正的存儲配置,以避免做store.load()和store.sync()。