0

サーバーからデータを取得し、モデルを 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 () {


//                            }
                        },

ログインボタンを押したときにモデルをローカルストレージと同期するにはどうすればよいですか?解決策を教えてください

4

3 に答える 3

2

モデルオブジェクトを作成するときに、モデルオブジェクトにダーティフラグを設定します。

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

また、ストア構成に対してautoSync:trueおよびautoLoad:trueを設定して、store.load()およびstore.sync()を実行する必要をなくすこともできます。

于 2013-03-10T07:35:59.403 に答える
1

問題を誤解しているかもしれませんが、storeId「blueButtonStore」などのプロパティをストアに追加して、次のように同期できます。

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

ローカルストレージに存在するものをストアにロードするには、次を使用します

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

それがあなたの問題に関係していない場合はお知らせください。

于 2013-03-05T05:03:58.667 に答える
0

あなたの店はbluebutton.store.BlueButton.LoginLS?

電話してみてください:

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

私のために働く手順:
私の店の名前は、例:MyApp.store.settings.Settingsです。
このストアを取得するには、次のように呼び出すだけです。これvar settings = Ext.getStore('Settings');
で、アイテムをストアに追加、削除してから同期できます。settings.sync();

ストアが app.js で定義されているかどうかを確認してください。

于 2013-04-10T10:55:34.860 に答える