从控制器调用存储中的api。 Ext Js

时间:2017-08-03 03:20:47

标签: extjs

我在控制器中有这个功能,点击按钮时可以正常工作:

 onSaveClick: function () {
    var form = this.lookupReference('userForm');

    if (form.isValid()) {

        //form.getValues();
    }
},

我想将值传递给我的商店,其中包含以下代码:

proxy: {
    type: 'rest',
    url: '/api/Users',
    api: {
        create: '/Users/PostUser',
        read: '/Users/GetListUsers',
        update: '/Users/PutUser',
        destroy: '/Users/DeleteUser'
    },
    writer: {
        type: 'json',
        writeAllFields: false
    }
}

我想调用api create并从控制器传递我的数据。我该怎么做呢?我对Sencha ExtJs很新。

1 个答案:

答案 0 :(得分:1)

首先,您需要在商店中添加记录,然后您可以在商店调用SELECT f.carrier, f.id, ROW_NUMBER() OVER (PARTITION BY f.carrier ORDER BY f.id) as flight_sequence_number FROM flights f; ,这将调用创建API ,因为Ext发现那里是添加到商店的新记录。

sync()

示例代码:



 Ext.getStore('<yourStoreId>').add(form.getValues()); // adding the record to the store
 Ext.getStore('<yourStoreId>').sync(); // it will call create api as we have a new record added
&#13;
Ext.application({
    name : 'Fiddle',

    launch : function() {
    Ext.create('Ext.data.Store', {
    storeId:'simpleStore',
      fields : ['first','last'],
      proxy: {
      type: 'rest',
    url: '/api/Users',
    api: {
        create: '/Users/PostUser',
        read: '/Users/GetListUsers',
        update: '/Users/PutUser',
        destroy: '/Users/DeleteUser'
    },
    writer: {
        type: 'json',
        writeAllFields: false
    }
}
});
    Ext.create('Ext.form.Panel', {
    title: 'Simple Form',
       // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'First Name',
        name: 'first',
        allowBlank: false
    },{
        fieldLabel: 'Last Name',
        name: 'last',
        allowBlank: false
    }],

    // Reset and Submit buttons
    buttons: [ {
        text: 'Submit',
        handler: function() {
            var form = this.up('form').getForm();
            if (form.isValid()) {
             Ext.getStore('simpleStore').add(form.getValues());
             Ext.getStore('simpleStore').sync();
            }
        }
    }],
    renderTo: Ext.getBody()
});
}
});
&#13;
&#13;
&#13;