首先我请你对我宽容一点:我只是一个可怜的 ext-js 和 javascript 新手......
我正在尝试适应我的需要 ext-js 中的无限滚动网格示例。我在 sencha ext-js 中定义了以下商店:
Ext.define('AM.store.M2MResources', {
extend: 'Ext.data.Store',
requires: 'Ext.direct.*', // use ext-direct for binding
model: 'AM.model.M2MResource',
autoLoad: true,
paramsAsHash:false,
autoSave: false,
pageSize: 25,
// allow the grid to interact with the paging scroller by buffering
buffered: true,
proxy: {
type: 'direct',
api: {
// create : undefined,
read : M2MResourceServlet.getM2Mresources,
// update : undefined,
// destroy : undefined
},
extraParams: {
total: 100
},
root: 'data',
fields: [{name:'label'}, {name:'address_unique'}, {name:'address_network'}, {name:'status'}],
paramOrder: 'page, start, limit',
reader: {
type: 'json',
root: 'data',
successProperty: 'success',
totalProperty: 'totalCount'
},
writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields: true,
listful: true
}
)
}
});
与此 directJNgine 服务器对应:
public class M2MResourceServlet {
public static class ResourceData{
public String label;
public String address_unique;
public String address_network;
public String status;
}
public static class DirectStoreResult{
ResourceData[] data;
public int totalCount;
public boolean success = true;
public DirectStoreResult(ResourceData[] data, int totalCount) {
super();
this.data = data;
this.totalCount = totalCount;
}
}
static int counter = 0;
@DirectMethod
public DirectStoreResult getM2Mresources( Integer page, Integer start, Integer limit ) {
ArrayList<ResourceData> result = new ArrayList<ResourceData>();
// fill result list...
DirectStoreResult r = new DirectStoreResult(result.toArray(new ResourceData []{}),limit);
return r;
}
}
然后我指定了以下模型:
Ext.define('AM.model.M2MResource', {
extend: 'Ext.data.Model',
fields: [
{name:'label' },
{name:'address_unique' },
{name:'address_network' },
{name:'status' }
]
});
有了这个,我想将数据加载到以下网格中:
Ext.define('AM.view.resgrid.M2MResources', {
extend: 'Ext.grid.Panel',
alias: 'widget.m2mresources',
title: 'All Resources Here',
verticalScrollerType: 'paginggridscroller',
store: 'M2MResources',
initComponent: function() {
console.log('initComponent function in View has been called...');
this.columns = [
{header: 'friendly name',dataIndex: 'label',flex: 1, sortable: true},
{header: 'address unique', dataIndex: 'address_unique',flex: 1},
{header: 'address network', dataIndex: 'address_network', flex: 1},
{header: 'node status',dataIndex: 'status',flex: 1}
];
this.callParent(arguments);
Ext.getStore('M2MResources').guaranteeRange(0, 100);
}
});
不幸的是,商店似乎从不加载数据:网格面板显示“正在加载...”符号并且没有显示任何数据项。我怀疑问题出在我的直接方法返回的 json 中。客户端我得到以下 json 数据记录:
你能建议如何解决这个问题吗?谢谢!