extjs 将额外的参数发送到 restapi 时出现问题



我有一个 rest api,我想从 extjs 中读取。这些是其余 API 所需的参数:

params = {
   sort: 'idlevel', 
   filter: {
      active: true, 
      idup: {
        'null': 0
      }
   }
}

如您所见,这是一个非常简单的Javascript对象。这些参数的工作方式类似于另一个使用 Reactjs 构建的应用程序的魅力。从 Extjs 商店,我像这样从我的商店发送它们:

...
 proxy: {
        type: 'ajax',
        headers: {
           'Accept': '*/*',
           'Cache-Control': 'no-cache',
           'Content-Type': 'application/json',
           'Authorization': localStorage.token
        },
        extraParams: {
          sort: 'idlevel', 
          filter: {
             active: true, 
             idup: {
               'null': 0
             }
          }
       }
   ...

问题是这返回了验证失败错误。当我进入浏览器的网络历史记录时,我看到以下查询字符串参数:

_dc: 1556221645266
filter: [object Object]
filter: true
sort: idlevel
page: 1
start: 0
limit: 25

我不知道为什么 Extjs 会把extraParams中的 javascript 对象变成这个奇怪的东西。所以我的问题是:我怎样才能告诉 Extjs 以正确的方式假设这些参数?我在这里错过了一些琐碎的东西吗?

更新:这是使用 react 时的查询字符串输出:

sort: idlevel
filter[active]: true

如果 react 中的查询字符串是这样的:

sort: idlevel
filter[active]: true

那么在extjs ajax代理中应该是:

    var myStore = Ext.create('Ext.data.Store', {
        autoLoad: true,
        fields: ['a'],
        noCache: true,
        remoteSort: false,
        remoteFilter: false,
        pageSize: 0,
        proxy: {
            url: "http://example.xyz",
            noCache: false,
            type: 'ajax',
            headers: {
                'Accept': '*/*',
                'Cache-Control': 'no-cache',
                'Content-Type': 'application/json',
                'Authorization': localStorage.token
            },
            extraParams: {
                sort: 'idlevel',
                'filter[active]': true
            }
        }
    });

您通过 url 发送一个对象,它希望是纯文本,我的建议是在您的对象中使用 JSON.stringify(),如下所示

    extraParams: {
      sort: 'idlevel', 
      filter: JSON.stringify({
         active: true, 
         idup: {
           'null': 0
         }
      })
   }

然后在后端,您可以在对象中再次转换字符串

最新更新