Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带参数的extjs post_Extjs_Datastore - Fatal编程技术网

带参数的extjs post

带参数的extjs post,extjs,datastore,Extjs,Datastore,我正在创建一个数据存储,它将从服务器加载数据。我想知道如何将参数传递给代理 var dataStore = new Ext.data.JsonStore({ proxy:'productSearch.php', root:'products', fields:['title', 'image', 'inStock', 'price', 'category', 'manufacturer'] }); 我通常是这样做的 var dataStore = new Ext.data.JsonStore(

我正在创建一个数据存储,它将从服务器加载数据。我想知道如何将参数传递给代理

var dataStore = new Ext.data.JsonStore({
proxy:'productSearch.php',
root:'products',
fields:['title', 'image', 'inStock', 'price', 'category', 'manufacturer']
});

我通常是这样做的

var dataStore = new Ext.data.JsonStore({
  url: 'productSearch.php'
  root: 'products',
  baseParams: {  //here you can define params you want to be sent on each request from this store
    param1: 'value1',
    param2: 'value2'
  },
  fields: [...]
});

dataStore.load({
  params: {  //here you can define params on 'per request' basis
    param3: 'value3'
  }
});
我还喜欢这样定义字段:

fields: [
  {name: 'title', mapping: 'title', type: 'string'},
  {name: 'image', mapping: 'image', type: 'string'},
  {name: 'inStock', mapping: 'inStock', type: 'bool'},
  {name: 'price', mapping: 'price', type: 'float'},
  {name: 'category', mapping: 'category', type: 'int'},
  {name: 'someDate', mapping: 'someDate', type: 'date', dateFormat: 'Y-m-d'},
]
这里有两件事:

  • 我分配类型,以便存储区加载正确的数据类型。它甚至会将字符串日期转换为JavaScript Date()对象

  • 我使用“mapping”参数来告诉JSON中的哪些字段与存储中的哪些字段相匹配。如果由于任何原因JSON格式发生更改,我只需要在这里做一个更改


  • 我通常是这样做的

    var dataStore = new Ext.data.JsonStore({
      url: 'productSearch.php'
      root: 'products',
      baseParams: {  //here you can define params you want to be sent on each request from this store
        param1: 'value1',
        param2: 'value2'
      },
      fields: [...]
    });
    
    dataStore.load({
      params: {  //here you can define params on 'per request' basis
        param3: 'value3'
      }
    });
    
    我还喜欢这样定义字段:

    fields: [
      {name: 'title', mapping: 'title', type: 'string'},
      {name: 'image', mapping: 'image', type: 'string'},
      {name: 'inStock', mapping: 'inStock', type: 'bool'},
      {name: 'price', mapping: 'price', type: 'float'},
      {name: 'category', mapping: 'category', type: 'int'},
      {name: 'someDate', mapping: 'someDate', type: 'date', dateFormat: 'Y-m-d'},
    ]
    
    这里有两件事:

  • 我分配类型,以便存储区加载正确的数据类型。它甚至会将字符串日期转换为JavaScript Date()对象

  • 我使用“mapping”参数来告诉JSON中的哪些字段与存储中的哪些字段相匹配。如果由于任何原因JSON格式发生更改,我只需要在这里做一个更改