Ext.ux.data.writer.FormParam,针对Ext.data.writer.Json这个类进行的修改,不同之处看红色标记除:
/**
* @class Ext.data.writer.Json
This class is used to write {@link Ext.data.Model} data to the server in a JSON format.
The {@link #allowSingle} configuration can be set to false to force the records to always be
encoded in an array, even if there is only a single record being sent.
* @markdown
*/
Ext.define('Ext.ux.data.writer.FormParam', {
extend: 'Ext.data.writer.Writer',
alias: 'writer.formParam',
/**
* @cfg {String} root The HTTP parameter name by which JSON encoded records will be passed to the server if the
* {@link #encode} option is `true`.
*/
root: undefined,
/**
* @cfg {Boolean} [encode=false] Configure `true` to send record data (all record fields if {@link #writeAllFields} is `true`)
* as a JSON encoded HTTP parameter named by the {@link #root} configuration.
*
* The encode option should only be set to true when a {@link #root} is defined, because the values will be
* sent as part of the request parameters as opposed to a raw post. The root will be the name of the parameter
* sent to the server.
*/
encode: false,
/**
* @cfg {Boolean} [allowSingle=true] Configure with `false` to ensure that records are always wrapped in an array, even if there is only
* one record being sent. When there is more than one record, they will always be encoded into an array.
*/
allowSingle: true,
/**
* @cfg {Boolean} [expandData=false] By default, when dot-delimited field {@link #nameProperty mappings} are
* used (e.g. `name: 'myProperty', mapping: 'my.nested.property'`) the writer will simply output a flat data
* object containing the mapping string literal as the property name (e.g. `{ 'my.nested.property': 'foo' }`).
*
* Mappings are used to map incoming nested JSON to flat Ext models. In many case, the data output by the
* writer should preferrably match the original nested data format. Setting this config to `true` will ensure
* that the output will instead look like `{ my: { nested: { property: 'foo' }}}`. The output is generated
* by {@link #getExpandedData}, which can optionally be overridden to apply more customized logic.
*/
expandData: false,
/**
* @protected
* The Reader classes support dot-delimited data mappings for extracting nested raw data into fields, so the
* writer must support converting the flat {@link Ext.data.Model} structure back into the original nested data
* format. Using the same mappings when available, the Writer will simply split each delimiter into a nested
* object in the output, which should exactly match the input format. For example, record data like this:
*
* my.nested.property: 'foo',
* my.nested.another: 'bar',
* my.somethingElse: 123
*
* should write out as...
*
* my: {
* nested: {
* property: 'foo',
* another: 'bar
* },
* somethingElse: 123
* }
*
* This behavior is governed by the {@link #expandData} config. By default, this option is `false` for
* compatibility reasons, and will output a flat structure matching the flat record format. Setting this config
* to `true` will enable the expanded mapping behavior as shown here. This method could also be overridden
* to provide an even more customized output data structure.
*/
getExpandedData: function(data) {
var dataLength = data.length,
i = 0,
item,
prop,
nameParts,
j,
tempObj,
toObject = function(name, value) {
var o = {};
o[name] = value;
return o;
};
for (; i < dataLength; i++) {
item = data[i];
for (prop in item) {
if (item.hasOwnProperty(prop)) {
// e.g. my.nested.property: 'foo'
nameParts = prop.split('.');
j = nameParts.length - 1;
if (j > 0) {
// Initially this will be the value 'foo'.
// Equivalent to rec['my.nested.property']
tempObj = item[prop];
for (; j > 0; j--) {
// Starting with the value above, we loop inside out, assigning the
// current object as the value for the parent name. Work all
// the way up until only the root name is left to assign.
tempObj = toObject(nameParts[j], tempObj);
}
// At this point we'll have all child properties rolled up into a single
// object like `{ nested: { property: 'foo' }}`. Now add the root name
// (e.g. 'my') to the record data if needed (do not overwrite existing):
item[nameParts[0]] = item[nameParts[0]] || {};
// Since there could be duplicate names at any level of the nesting be sure
// to merge rather than assign when setting the object as the value:
Ext.Object.merge(item[nameParts[0]], tempObj);
// Finally delete the original mapped property from the record
delete item[prop];
}
}
}
}
return data;
},
//inherit docs
writeRecords: function(request, data) {
var root = this.root;
if (this.expandData) {
data = this.getExpandedData(data);
}
if (this.allowSingle && data.length === 1) {
// convert to single object format
data = data[0];
}
if (this.encode) {
if (root) {
// sending as a param, need to encode
request.params[root] = Ext.encode(data);
} else {
for(var p in data){
request.params[p] = data[p];
}
}
} else {
// send as jsonData
request.jsonData = request.jsonData || {};
if (root) {
request.jsonData[root] = data;
} else {
request.jsonData = data;
}
}
return request;
}
});
Ext.data.writer.Json当设置了encode=true,但是没有设置root值的时候会:
//<debug> Ext.Error.raise('Must specify a root when using encode'); //</debug>
我将其所有的属性以表单参数形式进行传递。
for(var p in data){ request.params[p] = data[p]; }
当然用jsonData的形式传递给后台已经足够使用。这是只是另一种传递方式而已。切勿纠结!
相关推荐
Ajax+JSON 改善Form提交数据的 UI 交互设计
[08]EXTJS4.0的Ajax.003.zip (53.77M)[08]EXTJS4.0的Ajax.002.zip [08]EXTJS4.0的Ajax.001.zip 第九讲:extjs4.0的core包和Ext类 [09]EXTJS4.0的core包和Ext类.003.zip (60.22M)[09]EXTJS4.0的core包和Ext类.002....
[08]EXTJS4.0的Ajax.003.zip (53.77M)[08]EXTJS4.0的Ajax.002.zip [08]EXTJS4.0的Ajax.001.zip 第九讲:extjs4.0的core包和Ext类 [09]EXTJS4.0的core包和Ext类.003.zip (60.22M)[09]EXTJS4.0的core包和Ext类.002...
ajax同步请求一般下面这样: 代码如下: var conn = Ext.lib.Ajax.getConnectionObject().conn; conn.open(“POST”, ‘http://localhost:8080/struts2study/TreeDDGet?node=-1’,false); // 这里的conn对象其实就是 ...
第八讲: EXTJS4.0的Ajax 第九讲: EXTJS4.0的Core包和Ext类 第十讲: EXTJS4.0的Util包 ***************第二部分高级组件**************** 第十一讲: EXTJS4.0的高级组件Grid(上) 第十二讲: EXTJS4.0的MVC重构十一讲...
[08]EXTJS4.0的Ajax.003.zip (53.77M)[08]EXTJS4.0的Ajax.002.zip [08]EXTJS4.0的Ajax.001.zip 第九讲:extjs4.0的core包和Ext类 [09]EXTJS4.0的core包和Ext类.003.zip (60.22M)[09]EXTJS4.0的core包和Ext类.002....
16. extJs 2.0学习笔记(Ajax篇) 38 17. extJs 2.0学习笔记(Ext.data序论篇) 39 18. extJs 2.0学习笔记(Ext.Panel终结篇) 40 19. extJs 2.0学习笔记(事件注册总结篇) 45 20. extJs 2.0学习笔记(Ext.Panel篇一) 48 21....
3、通过实现角色管理、用户管理、部门管理三个基础的功能模块,演示了Viewport、Container、Panel、Grid、Window、Form、Tree等常用组件的用法,以及border、column、form、fit、accordion、hbox等常用布局方式;...
4.3.3 Ajax模式的表单数据提交 4.3.4 标准模式的表单数据提交 4.3.5 使用Direct技术 4.4 本章小结 第5章 面板及布局类 5.1 面板panel 5.1.1 认识Ext.panel.Panel 5.1.2 Ext.panel.Panel的主要功能 5.1.3 ...
12.1.3 Ext.Ajax.request提交XML数据 12.2 Ext.Updater基础 12.2.1 Ext.Updater.update方法 12.2.2 Ext.Updater.update操作示例 12.3 利用Ajax优化Web应用框架 12.3.1 多级联动菜单 12.3.2 Ajax修改用户密码 ...
二、Ext.form.FormPanel类 93 三、提交表单至服务器 97 四、小结 100 第十六章:更多表单组件 102 一、您能说出哪些表单组件呢? 102 二、表单组件关系图 102 三、组件配置选项介绍 103 四、完整源代码 107 五、小结...
16. extJs 2.0学习笔记(Ajax篇) 38 17. extJs 2.0学习笔记(Ext.data序论篇) 39 18. extJs 2.0学习笔记(Ext.Panel终结篇) 40 19. extJs 2.0学习笔记(事件注册总结篇) 45 20. extJs 2.0学习笔记(Ext.Panel篇一) 48 21....
25、Ext.Ajax类 ………………………… 22 26、Ext.data.Record类 ………………… 23 27、Ext.data.DataProxy类 …………… 24 28、Ext.data.HttpProxy类 …………… 24 29、Ext.data.MemoryProxy类 ……… 25 30、...
12.1.3 Ext.Ajax.request提交XML数据 12.2 Ext.Updater基础 12.2.1 Ext.Updater.update方法 12.2.2 Ext.Updater.update操作示例 12.3 利用Ajax优化Web应用框架 12.3.1 多级联动菜单 12.3.2 Ajax修改用户密码 ...
EXTJS 学习笔片段1 Form ComboBox 远程ComboBox 替代页面上已经存在的Select控件 Grid EditorGridPanel 使用本地store Toolbar工具菜单创建 分页工具栏创建 ... 弹出处理window窗口(模态窗口) ...Ajax提交
…….30 5.5 Form布局……….…………………………………………………………………………………………..………32 5.6 Accordion布局……….……………………………………………………………………………………...
但是对于Ext.Ajax.request来说 waitMsg 并不起作用。 fp.form.submit({ url : '', waitTitle : [性别]修改, waitMsg : '正在提交数据,请稍后... ...', success : function(form, action) { Ext.MessageBox....
需求来源是这样的:上传一个很大的excel文件到server, server会解析这个excel, 然后一条一条的插入到...当用户点“上传”之后,form被提交给uploadController.jsp,同时用js启动一个ajax请求到processController.j
formpanel可以这样使用,api上的例子: 代码如下: var panel=Ext.create(‘Ext.form.Panel’, { title: ‘Simple Form’, bodyPadding: 5, width: 350, // 将会通过 AJAX 请求提交到此URL //url: ‘save-form.php’,...