javascript 如何阻止 ext-js 向我的 JSON 查询添加 limit=25?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5199947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I stop ext-js from adding limit=25 to my JSON query?
提问by Duke Dougal
The following code is working. The problem is the request is being sent with &_dc=1299207914646&limit=25 appended to every request sent to the server. Nothing I can do changes the limit=25. Ideally I want no additional parameters sent to the server. I would make do however with being able to set the limit to 10000 or something. I AM able to add other parameters but nothing I do removes the limit=25. I would also like to get rid of the &_dc parameter although I don't know why it has been added it is not causing a problem.
以下代码正在运行。问题是发送请求时将 &_dc=1299207914646&limit=25 附加到发送到服务器的每个请求。我无能为力改变限制= 25。理想情况下,我不希望将其他参数发送到服务器。但是,我可以将限制设置为 10000 之类的。我可以添加其他参数,但我所做的任何事情都不会删除 limit=25。我也想去掉 &_dc 参数,虽然我不知道为什么添加它并没有引起问题。
Any ideas?
有任何想法吗?
note: some weird problem with code formatting below?
注意:下面的代码格式有一些奇怪的问题?
Thanks
谢谢
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.panel.*'
]);
Ext.onReady(function(){
Ext.regModel('Image_', { // window.Image is protected in ie6 !!!
fields: ['id', 'key', 'value']
});
var store = new Ext.data.JsonStore({
model: 'Image_',
proxy: {
type: 'ajax',
var store = new Ext.data.JsonStore({
model: 'Image_',
proxy: {
type: 'ajax',
autoload: 'false',
url: '/couchdb/test/_design/blah/_view/by_surname2?startkey=%22r%22&endkey=%22r\u9999%22',
reader: {
type: 'json',
root: 'rows'
}
}
});
store.load();
var listView = new Ext.grid.GridPanel({
width:425,
height:250,
collapsible:true,
title:'Simple ListView <i>(0 items selected)</i>',
renderTo: Ext.getBody(),
store: store,
multiSelect: true,
viewConfig: {
emptyText: 'No images to display'
},
headers: [{
text: 'File',
flex: 50,
dataIndex: 'value'
},{
text: 'Last Modified',
flex: 35,
dataIndex: 'key'
},{
text: 'Size',
dataIndex: 'id',
flex: 15,
cls: 'listview-filesize'
}]
});
// little bit of feedback
listView.on('selectionchange', function(view, nodes){
var l = nodes.length;
var s = l != 1 ? 's' : '';
listView.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
});
});
回答by jprism
In your Proxy, set
在您的代理中,设置
limitParam: undefined,
pageParam: undefined,
startParam: undefined,
noCache: false,
回答by Abdel Raoof
You can modify your store limit when you load the store.
您可以在加载商店时修改商店限制。
store.load({params:{limit:50}});
In this case, I am asking to set the limit to 50. _dc=1299207914646 is unique cache-buster param added to GET requests. If you don't want to have them in the url, you can disable them by setting disableCachingparameter to false.
在这种情况下,我要求将限制设置为 50。_dc=1299207914646 是添加到 GET 请求的唯一缓存破坏参数。如果您不想在 url 中包含它们,您可以通过将disableCaching参数设置为 false来禁用它们。
But I would recommend you to set the method of you store to POST and pass the parameters using POST rather than GET method. That way you can have clean URLs and also hide the data being sent.
但我建议您将存储方法设置为 POST 并使用 POST 而不是 GET 方法传递参数。这样您就可以拥有干净的 URL 并隐藏正在发送的数据。
回答by Sergey Novikov
You can override getParamsmethod of the Ext.data.proxy.Server.
您可以覆盖getParams的方法Ext.data.proxy.Server。
For example, in my project I added custom boolean parameter embeddedParamsand if I dont want to add ExtJS parameters to a request I set it to falsein a store proxy:
例如,在我的项目中,我添加了自定义布尔参数embeddedParams,如果我不想将 ExtJS 参数添加到请求中,我将其设置为false在商店代理中:
/**
* Added embeddedParams option
*/
Ext.define('Ext.lib.overrides.ServerProxy', {
override: 'Ext.data.proxy.Server',
/**
* Add or not pagination, grouping, sorting and filtering parameters to the request. Defaults to true.
*/
embeddedParams: true,
/**
* @private
* Copy any sorters, filters etc into the params so they can be sent over the wire
*/
getParams: function (operation) {
var me = this,
params = {},
isDef = Ext.isDefined,
groupers = operation.groupers,
sorters = operation.sorters,
filters = operation.filters,
page = operation.page,
start = operation.start,
limit = operation.limit,
simpleSortMode = me.simpleSortMode,
simpleGroupMode = me.simpleGroupMode,
pageParam = me.pageParam,
startParam = me.startParam,
limitParam = me.limitParam,
groupParam = me.groupParam,
groupDirectionParam = me.groupDirectionParam,
sortParam = me.sortParam,
filterParam = me.filterParam,
directionParam = me.directionParam,
hasGroups, index;
if (me.embeddedParams && pageParam && isDef(page)) {
params[pageParam] = page;
}
if (me.embeddedParams && startParam && isDef(start)) {
params[startParam] = start;
}
if (me.embeddedParams && limitParam && isDef(limit)) {
params[limitParam] = limit;
}
hasGroups = me.embeddedParams && groupParam && groupers && groupers.length > 0;
if (hasGroups) {
// Grouper is a subclass of sorter, so we can just use the sorter method
if (simpleGroupMode) {
params[groupParam] = groupers[0].property;
params[groupDirectionParam] = groupers[0].direction || 'ASC';
} else {
params[groupParam] = me.encodeSorters(groupers);
}
}
if (me.embeddedParams && sortParam && sorters && sorters.length > 0) {
if (simpleSortMode) {
index = 0;
// Group will be included in sorters, so grab the next one
if (sorters.length > 1 && hasGroups) {
index = 1;
}
params[sortParam] = sorters[index].property;
params[directionParam] = sorters[index].direction;
} else {
params[sortParam] = me.encodeSorters(sorters);
}
}
if (me.embeddedParams && filterParam && filters && filters.length > 0) {
params[filterParam] = me.encodeFilters(filters);
}
return params;
}
});
Usage:
用法:
store: Ext.create('Ext.data.Store', {
...
proxy: {
...
type: 'ajax', // or 'direct', 'jsonp' / 'scripttag'
embeddedParams: false
}
})
回答by Orbit
add the limit property to your store...
将限制属性添加到您的商店...
limit:50,
and might not hurt to try pagesize....
并可能不会伤害尝试 pagesize ....
pagesize:50
and see if either of these help.
看看这些是否有帮助。
Edit : also try
编辑:也试试
pageParam:undefined,
in your proxy.
在您的代理中。
found that last piece from...
发现最后一块来自...
回答by Nick
You can modify the limit param using
您可以使用修改限制参数
store.proxy.limitParam=null;
回答by dmulvi
To remove the _dc parameter on extjs 4 you can set:
要删除 extjs 4 上的 _dc 参数,您可以设置:
noCache: false
or just uncheck the box if you're using architect 2.
或者如果您使用的是建筑师 2,则取消选中该框。
回答by Fabrice Boyer
Specifically for Json, to get rid of _dcparameter, in your proxy object, set the config option given by Tharahan:
特别是对于 Json,要摆脱_dc参数,在您的代理对象中,设置 Tharahan 给出的配置选项:
proxy: {
type: 'ajax',
api: {
read: 'app/data/something.json',
update: 'app/data/something.json'
},
reader: {
type: 'json',
...
},
writer: {
type: 'json',
...
},
noCache: false
}
EDIT: (sorry, I did not look at the post date, but lost so much time with it) Please note that the global Ext.Loader.setConfig({disableCaching: false});does notaffect subclasses of Ext.data.proxy.Serverwhich need this specific option (at least in development with sencha touch 2.2.0).
编辑:(抱歉,我没有看发布日期,但是浪费了很多时间)请注意,全局Ext.Loader.setConfig({disableCaching: false});不会影响Ext.data.proxy.Server需要此特定选项的子类(至少在使用 sencha touch 2.2.0 进行开发时)。

