Search code examples
extjsextjs4extjs4.2

store sync data does not work


my store's code

Ext.define('Console.store.SubjectMaterial.DetailStore', {
extend: 'Ext.data.Store',

model: 'Console.model.SubjectMaterial.DetailModel',

proxy: {
    actionMethods: 'POST',
    type: 'ajax',

    api: {
        create: './modules/source/controller/SubjectMaterial/insertDetail.php',
        read: './modules/source/store/SubjectMaterial/selectDetail.php',
        destroy: './modules/source/controller/SubjectMaterial/deleteDetail.php'
    },

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

    writer: {
        type: 'json',
        root: 'data',
        encode: true
    }
},

sorters: {
    direction: 'ASC',
    property: 'material_name'
},

remoteSort: true,
autoLoad: false,
autoSync: true
});

my model's code

Ext.define('Console.model.SubjectMaterial.DetailModel',{
extend:'Ext.data.Model',
fields:[
{
    name:'material_id',
    type:'string'
},{
    name:'material_name',
    type:'string'
},{
    name:'material_version',
    type:'string'
},{
    name:'material_picture',
    type:'string'
},{
    name:'material_detail',
    type:'string'
},{
    name:'material_url',
    type:'string'
},{
    name: 'material_size',
    type: 'string'
},{
    name: 'material_author',
    type: 'string'
},{
    name: 'subject_share',
    type: 'string'
},{
    name: 'subject_secure',
    type: 'string'
},{
    name: 'material_create_date',
    type: 'string'
},{
    name: 'material_update_date',
    type: 'string'
}]
});

my controller's code

detailInsertConfirm: function(obj, e, eOpts) {

    var masterSelectedRecord =       Ext.getCmp('sumagridmaster').getSelectionModel().getSelection()[0];
    var detailStore = Ext.getCmp('sumagriddetail').store;
    var actionPanel = obj.up('sumaactionpanel');
    var gridPanel = obj.up('sumaformdetailinsert');
    // console.log(gridPanel);
    // var formPanel = gridPanel.getForm();
    //insert

    detailStore.add(gridPanel.getSelectionModel().getSelection());
    // detailStore.add(masterSelectedRecord);
    console.log(detailStore.data);
    // console.log(gridPanel.getSelectionModel().getSelection());
    detailStore.sync({

        callback: function(batch, options) {
            // body...
            console.log('this is callback.');
        },

        success: function(batch, options) {
            console.log('this is success.');
            Ext.MessageBox.show({
                title: MSG['universal_msg_box_header_text'],
                icon: Ext.MessageBox.INFO,
                msg: MSG['universal_msg_box_content_insert_success'],
                closable: false,
                buttons: Ext.MessageBox.OK,
                fn: function(buttonId,text,opt){
                    if (buttonId == 'ok') {
                        detailStore.reload();
                    }
                }
            });
        },

        failure: function(batch, options) {
            console.log('this is failure.');
            Ext.MessageBox.show({
                titel: MSG['universal_msg_box_header_text'],
                icon: Ext.MessageBox.ERROR,
                msg: MSG['universal_msg_box_content_insert_fail'],
                closable: false,
                buttons: Ext.MessageBox.OK
            });
        }
    });

And I don't know why my controll's detailStore.sync cannot work.

Doesn't have any error code.

Just totally no Response....

And I always check my network.

It have no requset.


Solution

  • I'm not quite sure what you're asking. For sync to work you need to change something in the store (modify, delete, add), you need a writer on the proxy and when you then call store.sync() the request(s) is sent to the server. Only after that a response arrives.