I'm trying to make EXT JSON store to send data using JSON, however it does not seem to be working. Here is simple code:
var myStore = new Ext.data.Store({
//model: 'User',
proxy: {
type: 'ajax',
url: '/users.svc',
reader: {
type: 'json',
root: 'users'
},
writer: {
type: 'json',
root: 'data'
},
actionMethods: {
create: 'POST', read: 'POST', update: 'POST', destroy: 'POST'
},
extraParams: { test: 'test' }
},
listeners: {
beforeload: function (store, operation, options) {
//alert(operation.params);
}
},
autoLoad: true
});
Since I defined JSON "writer", my expectation that parameterswould be send to server using JSON.
However it's still doing regular POST with following body:
test=test&page=1&start=0&limit=25
While my expectation is that POST should have the following body: {test:'test',page:1,start:0}
I would appreciate any help
P.S. I'm using EXTJS 4.0.7
I'm trying to make EXT JSON store to send data using JSON, however it does not seem to be working. Here is simple code:
var myStore = new Ext.data.Store({
//model: 'User',
proxy: {
type: 'ajax',
url: '/users.svc',
reader: {
type: 'json',
root: 'users'
},
writer: {
type: 'json',
root: 'data'
},
actionMethods: {
create: 'POST', read: 'POST', update: 'POST', destroy: 'POST'
},
extraParams: { test: 'test' }
},
listeners: {
beforeload: function (store, operation, options) {
//alert(operation.params);
}
},
autoLoad: true
});
Since I defined JSON "writer", my expectation that parameterswould be send to server using JSON.
However it's still doing regular POST with following body:
test=test&page=1&start=0&limit=25
While my expectation is that POST should have the following body: {test:'test',page:1,start:0}
I would appreciate any help
P.S. I'm using EXTJS 4.0.7
Share Improve this question edited Dec 25, 2015 at 12:32 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 3, 2012 at 17:39 user1247132user1247132 111 gold badge1 silver badge2 bronze badges2 Answers
Reset to default 2proxy.read always use params, NOT jsonData, so store.load can't post json
http://ahlearns.wordpress./2012/08/16/ext-js-4-load-a-data-store-using-json-params/
Ext.define('Ext.ux.data.proxy.JsonAjaxProxy', {
extend:'Ext.data.proxy.Ajax',
alias:'proxy.jsonajax',
actionMethods : {
create: "POST",
read: "POST",
update: "POST",
destroy: "POST"
},
buildRequest:function (operation) {
var request = this.callParent(arguments);
// For documentation on jsonData see Ext.Ajax.request
request.jsonData = request.params;
request.params = {};
return request;
},
/*
* @override
* Inherit docs. We don't apply any encoding here because
* all of the direct requests go out as jsonData
*/
applyEncoding: function(value){
return value;
}
});
Hope this helps!
Shift the proxy
definition to the model
.
E.g.
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'email'],
proxy: {
type: 'ajax',
url: '/users.svc',
reader: {
type: 'json',
root: 'users'
},
writer: {
type: 'json',
root: 'data'
},
actionMethods: {
create: 'POST', read: 'POST', update: 'POST', destroy: 'POST'
},
extraParams: { test: 'test' }
}
});
Then configure the store like so:
var myStore = new Ext.data.Store({
model: 'User'
});
The store will use the proxy specified in the model. Hope this helps!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745340000a4623282.html
评论列表(0条)