如何将服务器返回的json数据自动回填到我的form里头去?想必使用Ext Form组件的开发者都会遇到这样的问题。
解决的办法是:
(1) 将bean中的值使用json-lib转为json串返回给页面
(2) 使用Prototype提供的String.evalJSON()的方法将json数据装换为对象
备注:
Prototype 1.6 Complete API Reference中Chapter21关于String的evalJSON方法的说明:
evalJSON([sanitize = false]) -> object
Evaluates the JSON in the string and returns the resulting object.
(3) 调用form的setValues()方法将转换后的json对象填入到表单中即可
jsondata中的数据为
{"addAbility":"0","dataFilter":"level_type > 1","dataFilterDesc":"fsa as","deleteSql":"delete from BANK_LEVEL","description":"特斯塔","extractSql":"select * from BANK_LEVEL","insertSql":"delete from BANK_LEVEL","tableAlias":"机构级别","tableName":"BANK_LEVEL","type":"1","updateSql":"delete from BANK_LEVEL","userFilter":"sadf ","userFilterDesc":"as df"}
说明:bean中的属性名同表单中Field的名称
var data = jsondata.evalJSON();
formPanel.getForm().setValues(data);
此方法代码只需两行,比较light。
/////////////////////////////////////////////////////////////////////////////
That is the English version of my note: (sorry about the not nicely words)
How to fill the JSON data into the Ext Form component which from the server?
maybe all the base Ext developer face to this question.
Resolve:
The core of the code is only two lines.
var data = jsondata.evalJSON();
formPanel.getForm().setValues(data);
Explain:
(1) jsondata is the Server response data, and via the evalJSON method that transform it to the JavaScript Object.
(2) then call ur formPanel.getForm() to get the form,and use the form's setValues() method set the javabean's field value into the form's from the transform object
The method evalJSON is the Prototype 1.6 lib provide.There is the description:
Prototype 1.6 Complete API Reference Chapter21 about String's evalJSON method:
evalJSON([sanitize = false]) -> object
Evaluates the JSON in the string and returns the resulting object.
That's all, tks
分享到:
相关推荐
1、将form中的数据利用本工具转换成json格式的字符串,再通过ajax传给服务器,从而可以实现无刷新的form提交。; 2、通过AJAX从服务器得到json格式的数据,然后使用本工具解析数据填入form。从而可以实现无刷新的...
服务器返回json数据到客户端,android端可以解析
struts2向服务器返回json数据的一个简单Demo,便于理解
包含一个SSH框架实例和一个获取该服务器...APP把数据以hashmap形式传给服务器,服务器在对应action中取得对应的值,进行处理并返回给app对应的json字符串。 有任何问题发送至:970135203@qq.com 欢迎小伙伴们共同学习
Json4Ext是“AnyFo – Util”项目下的一个子项目,他提供了多个工具包,它让开发者轻松的通过构建一些简单的Java类,然后自动的将 这些Java类生成符合Ext要求的各种Json格式的字符串。 Json4Ext类简介 在Json4...
* 将web Form 的数据转化成json字符串的函数 * howwa@sina.com 根据网上搜的资料修改而成 * 2011-5-14 * 将web Form 采集的数据转化成json字符串 * 传入web form对象 * 输出由form元素名称及其值组成的json字符串 *...
1. 例子代码有两部分:androidJson是andoird的工程,inxdex.php是php服务器json数据产生部分代码。 2. 服务器端提供http(get)获取方式获取json数据的api例子,是用php写的。 4. android的apk给你说完成http数据...
Ext 中JsonLib 解析字符串 Ext 中JsonLib 解析字符串 Ext 中JsonLib 解析字符串
Jquery中使用ajax,表单post提交数据 插入oracle数据库, html对应的文件中 将form 表单数据 转化为json 格式
使用JQuery实现从JSON对象转换为form提交数据
Ext.form.field.ComboBox结合Java、JSON实现AutoComplete
通常前端通过POST请求向服务器端提交数据格式有4中,分别是”application/x-www-form-urlencoded”格式、” multipart/form-data”格式、”application/json”格式和”text/xml”格式。通常最常见的是”application/...
说明如何将数据转化为json传至前台,是一个很好的实例
android框架解析JSON数据放入ListView的例子
Android通过gson自动解析服务器返回的json数据
jq json 填充 form,根据名字匹配
java 通过发送json,post请求,返回json数据的方法 java 通过发送json,post请求,返回json数据的方法
java后端返回json给前端,包含对象JsonObject,JsonConfig,JsonArray.
只需要将dt传过来就能够生成json类型数据