传递extJs网格值来存储PHP脚本

时间:2022-08-24 11:39:08

I currently have a simple extJS Grid which is pulling data from a server and presenting it to the viewer. I would like to grab the value of the selected row, and then pass it to another PHP script for processing in order to display the results in another grid.

我现在有一个简单的extJS网格,它从服务器中提取数据并将其呈现给查看器。我想获取所选行的值,然后将其传递给另一个PHP脚本进行处理,以便在另一个网格中显示结果。

var roleInformationStore = Ext.create('Ext.data.Store', {
  autoLoad: true,
  autoSync: true,
  model: 'RoleInformation',
  proxy: {
    type: 'ajax',
    url: 'data.php',
    reader: {
      type: 'array',
    },
    writer: {
      type: 'json'
 }
}
});

var roleInformationGrid = Ext.create('Ext.grid.Panel', {
  store: roleInformationStore,
  width: '100%',
  height: 200,
  title: 'Roles',
  columns: [
  {
    text: 'Name',
    flex: 1,
    width: 100,
    sortable: false,
    hideable: false,
    dataIndex: 'role'
 }
 ],
 listeners: {
   cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
     roleInformationStore.proxy.extraParams = record.get('role');
    //Ext.Msg.alert('Selected Record', 'Name: ' + record.get('role'));
   }
 }
});

Using the listener in the current grid, I am able to get the value and show it using the alert method. Any suggestions on how to accomplish this?

使用当前网格中的侦听器,我可以获取值并使用alert方法显示它。有什么建议吗?

Thanks

谢谢

1 个解决方案

#1


2  

For this to work, extraParams has to be an object of key-value string pairs, because an URI has to be something like data.php?key1=value1&key2=value2.

要实现这一点,extraParams必须是键值字符串对的对象,因为URI必须是类似data.php?key1=value1&key2=value2的东西。

Style-wise, Sencha advises to use getters and setters, whenever possible.

在风格上,Sencha建议尽可能使用getter和setter方法。

Together, you get:

在一起,你会:

var store = Ext.getStore("roleInformationStore");
store.getProxy().setExtraParam("myRoleParamKey",record.get('role'));
store.load();

In PHP, you would get the parameter then using

在PHP中,您将获得参数然后使用。

$role = $_GET['myRoleParamKey'];

You can of course substitute myRoleParamKey for any alphanumeric literal you want, but make sure you use the same key on both server and client side. ;-)

当然,可以将myRoleParamKey替换任何你想要的字母数字文字,但是要确保在服务器和客户端都使用相同的键。:-)

Docs: setExtraParam

文档:setExtraParam

#1


2  

For this to work, extraParams has to be an object of key-value string pairs, because an URI has to be something like data.php?key1=value1&key2=value2.

要实现这一点,extraParams必须是键值字符串对的对象,因为URI必须是类似data.php?key1=value1&key2=value2的东西。

Style-wise, Sencha advises to use getters and setters, whenever possible.

在风格上,Sencha建议尽可能使用getter和setter方法。

Together, you get:

在一起,你会:

var store = Ext.getStore("roleInformationStore");
store.getProxy().setExtraParam("myRoleParamKey",record.get('role'));
store.load();

In PHP, you would get the parameter then using

在PHP中,您将获得参数然后使用。

$role = $_GET['myRoleParamKey'];

You can of course substitute myRoleParamKey for any alphanumeric literal you want, but make sure you use the same key on both server and client side. ;-)

当然,可以将myRoleParamKey替换任何你想要的字母数字文字,但是要确保在服务器和客户端都使用相同的键。:-)

Docs: setExtraParam

文档:setExtraParam