Last active
December 20, 2015 01:09
-
-
Save vote539/6047372 to your computer and use it in GitHub Desktop.
Sends data from your Sencha Touch or Ext JS proxy to your server using traditional POST variables (instead of JSON or XML).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Send data to the server as POST parameters. Refer to the documentation for {@link Ext.data.writer.Json} | |
for more details on proxy writers. Use "urlencode" as the writer type. For example, your store might | |
look something like this: | |
Ext.define('App.store.ExampleStore', { | |
extend: 'Ext.data.Store', | |
requires: [ | |
'App.model.ExampleModel' | |
], | |
config: { | |
autoLoad: true, | |
model: 'App.model.ExampleModel', | |
storeId: 'StudentScores', | |
proxy: { | |
type: 'rest', | |
url: 'example.php', | |
reader: { | |
type: 'json' | |
}, | |
writer: { | |
type: 'urlencode' | |
} | |
} | |
} | |
}); | |
*/ | |
/* Copyright 2013 Shane Carr | |
* Origin: https://gist.github.com/vote539/6047372 | |
* Based on: http://docs.sencha.com/touch/2.2.1/source/Json2.html | |
* Released under the X11/MIT License. */ | |
Ext.define("Ext.data.writer.UrlEncode", { | |
extend: "Ext.data.writer.Writer", | |
alternateClassName: "Ext.data.JsonWriter", | |
alias: "writer.urlencode", | |
config: { | |
allowSingle: true | |
}, | |
writeRecords: function(request, data){ | |
var params = request.getParams(), | |
allowSingle = this.getAllowSingle(); | |
if (!data || !(data.length || (allowSingle && Ext.isObject(data)))) { | |
return request; | |
} | |
if (allowSingle && data && data.length === 1) { | |
data = data[0]; | |
} | |
request.setParams(Ext.apply(data, params || {})); | |
return request; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment