【发布时间】:2015-01-15 00:30:03
【问题描述】:
我有一个 WebAPI 端点,它接受一些 JSON 对象作为参数并返回其他数据的集合。
这是一个工作请求:
POST http://mylocalmachine/api/Search
Accept: application/json
Content-Type: application/json
[
{'filterName' : 'ProductType','filterValue' : 'Shoes'}
]
在 Sencha Touch 中,我创建了一个存储 ('SearchFilters'),它将保存一组“过滤器”,我想将这些“过滤器”作为不同存储 ('MyData') 的请求正文发送。
Ext.define('MyApp.store.SearchFilters', {
extend: 'Ext.data.Store',
requires: [
'Ext.data.Field'
],
config: {
autoLoad: true,
data: [
{
filterName: 'ProductType',
filterValue: 'Shoes'
},
{
filterName: 'Region',
filterValue: 'NorthWest'
}
],
storeId: 'SearchFilters',
fields: [
{
name: 'filterName',
type: 'string'
},
{
name: 'filterValue',
type: 'string'
}
]
}
});
由于过滤器可以更改(或稍后从数据库加载),我试图在触发 Load 之前将 JSON 有效负载附加到“MyData”存储请求:
onStoreBeforeLoad: function(store, operation, eOpts) {
var filterData = Ext.getStore('SearchFilters').getData();
operation.request.setJsonData(Ext.JSON.encode(filterData));
}
我遇到的问题是 Ext.JSON.encode 函数在尝试从“SearchFilters”转换数据时抛出错误。错误是“堆栈溢出”,如果我设置断点并观察它,似乎有一个无限循环。显然,我抓取的不仅仅是“SearchFilter”商店中的少数过滤器记录。
将商店中的几条记录转换为 JSON 格式的正确方法是什么?
【问题讨论】:
-
可以使用store的
getRange方法。
标签: json extjs sencha-touch touch store