我正在访问一个REST服务,它公开了这两个资源,一个父资源和一个子资源:
/users
/users/{userId}/account
Run Code Online (Sandbox Code Playgroud)
因此资源"帐户"不嵌套在资源"用户"中,它必须由第二个请求访问.这里有REST API的例子,例如这里
我使用这些模型将用户及其帐户映射到Ext Js 4数据模型:
用户
Ext.define("MyApp.model.User", {
extend: "Ext.data.Model",
fields: [ { name: "id", type: "string" }],
associations: [{
model: "MyApp.model.Account",
name: "account",
type: "hasOne",
reader: "json",
getterName: "getAccount",
setterName: "setAccount",
foreignKey: "accountId"
}
],
proxy: {
type: "rest",
url: "/rest/users",
reader: {
type: "json",
totalProperty: "total",
root: "users"
}
}
});
Run Code Online (Sandbox Code Playgroud)
帐户
Ext.define("MyApp.model.Account", {
extend: "Ext.data.Model",
fields: [ { name: "id", type: "string" }],
belongsTo: "MyApp.model.User",
proxy: {
type: "rest",
reader: { type: "json"} …Run Code Online (Sandbox Code Playgroud) 我的应用程序(ExtJs 4.2.1)中有一个无限滚动网格面板,类似于此示例.用户可以单击刷新按钮,然后必须使用来自DB的数据更新网格的行.我在刷新按钮处理程序中调用store.load(),我的数据得到更新.这适用于网格面板的第一行(第1页的记录).但是如果用户向下滚动网格则不起作用.在store.load之后,网格将滚动位置重置为顶部.
我要求一个解决方案来重新加载商店并刷新网格,保持当前选择和当前滚动位置.好消息:我拥有商店中每条记录的全局索引.
这是我的代码,DB中有数千个条目.
网格面板:
Ext.define('MyApp.view.MyGrid', {
extend: 'Ext.grid.Panel',
requires:[ 'Ext.grid.plugin.BufferedRenderer'],
alias: 'widget.myGrid',
plugins: 'bufferedrenderer',
loadMask: true,
selModel: {
mode: 'MULTI',
pruneRemoved: false
},
itemSelector: 'div.workspaceItemSelector',
overItemCls: 'workspaceItemMouseOver',
trackOver: true,
autoScroll: true,
verticalScroller: { variableRowHeight: true },
defaultSortOrder: 'ASC',
// and some column definitions ...
});
Run Code Online (Sandbox Code Playgroud)
商店:
Ext.define('MyApp.store.MyStore', {
extend: 'Ext.data.Store',
autoLoad: false,
buffered: true,
pageSize: 100,
leadingBufferZone: 100,
remoteSort: true,
model: 'MyApp.model.MyModel',
storeId: 'myStore',
proxy: {
type: 'rest',
url: 'someUrl',
reader: { type: 'json', totalProperty: 'total', root: …Run Code Online (Sandbox Code Playgroud) 作为输入,我从用户获得一个字符串数组.我需要拆分这些行,使它们形成一个表,每行有相同数量的单元格.单元格应包含数字.我想确定单元格分隔符的最佳猜测,并将其作为默认值呈现给用户,如果猜测结果不好,则可以更改.
我假设它是以下之一:制表符,分号,空格或逗号.逗号很关键,因为它也被用作德语和其他文化中的小数点.输入可能包含诸如"1.0,2.0,3.0"或"1,0; 2,0; 3,0"之类的行
到目前为止我的原始解决方案是:
private char getSeparator(String[] rows) {
String firstRow = rows[0];
char[] possibleSeparators = new char[] {'\t',';',' ',','};
char separator = possibleSeparators[1];
for (int i=0;i<possibleSeparators.length;i++) {
if (firstRow.indexOf(separator) >= 0) {
separator = possibleSeparators[i];
break;
}
}
return separator;
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的启发式方法来获得细胞分离器的最佳匹配?
性能无关紧要!
extjs ×2
extjs4 ×2
datagrid ×1
extjs4.2 ×1
heuristics ×1
java ×1
parent-child ×1
parsing ×1
rest ×1
scroll ×1
text-parsing ×1