深入分析dwr中的DWRUtil.getValues(转)
来源:互联网 发布:chromas软件免费下载 编辑:程序博客网 时间:2024/06/15 12:40
关键词: ajax web开发(脚本和动态语言) dwr util.js dwrutil.getvalu
当你需要通过dwr完成类似提交form的操作,了解DWRUtil.getValues是必须的
/**
* Given a map, call getValue() for all the entries in the map using the entry key as an element id.
* Given a string or element that refers to a form, create an object from the elements of the form.
* @see http://getahead.ltd.uk/dwr/browser/util/getvalues
*/
DWRUtil.getValues = function(data) {
//定义ele变量,
var ele;
//如果ele是一个字符串通过 $函数转化一下,$函数的使用见我的上个帖子深入分析dwr中的DWRUtil.$
if (typeof data == "string") ele = $(data);
//如果ele是个HTML元素对象,通常应该是一个form对象
if (DWRUtil._isHTMLElement(data)) ele = data;
if (ele != null) {
//如果ele不是form对象,返回,只有form对象才有elements 属性
if (ele.elements == null) {
alert("getValues() requires an object or reference to a form element.");
return null;
}
//定义一个空对象reply
var reply = {};
//定义一个对象放key
var value;
//遍历form,将表单key-value放入reply,忽略<input type="image"/>
for (var i = 0; i < ele.elements.length; i++) {
if (ele[i].id != null) value = ele[i].id;
else if (ele[i].value != null) value = ele[i].value;
else value = "element" + i;
reply[value] = DWRUtil.getValue(ele[i]);
}
return reply;
}
//如果传入的参数对象不是表单对象,通常应该是与领域对象对应js对象
else {
//遍历对象属性,将与属性对应的页面元素值拷到js对象中
for (var property in data) {
// Are there any elements with that id or name
if ($(property) != null || document.getElementsByName(property).length >= 1) {
data[property] = DWRUtil.getValue(property);
}
}
return data;
}
};
总结
1)如果你需要使用ajax完成表单提交的操作,那么你应该使用DWRUtil.getValues,参数或者是个form对象,或者是个与领域对象对应的js对象
2)应该看到第二种用法的局限性,如果存在多个相同的表单或者是个复合的js对象,那么第二种用法是不合适的
3)第一种用法看似复杂,但更具灵活性
到底改如何选择取决于具体的应用
/**
* Given a map, call getValue() for all the entries in the map using the entry key as an element id.
* Given a string or element that refers to a form, create an object from the elements of the form.
* @see http://getahead.ltd.uk/dwr/browser/util/getvalues
*/
DWRUtil.getValues = function(data) {
//定义ele变量,
var ele;
//如果ele是一个字符串通过 $函数转化一下,$函数的使用见我的上个帖子深入分析dwr中的DWRUtil.$
if (typeof data == "string") ele = $(data);
//如果ele是个HTML元素对象,通常应该是一个form对象
if (DWRUtil._isHTMLElement(data)) ele = data;
if (ele != null) {
//如果ele不是form对象,返回,只有form对象才有elements 属性
if (ele.elements == null) {
alert("getValues() requires an object or reference to a form element.");
return null;
}
//定义一个空对象reply
var reply = {};
//定义一个对象放key
var value;
//遍历form,将表单key-value放入reply,忽略<input type="image"/>
for (var i = 0; i < ele.elements.length; i++) {
if (ele[i].id != null) value = ele[i].id;
else if (ele[i].value != null) value = ele[i].value;
else value = "element" + i;
reply[value] = DWRUtil.getValue(ele[i]);
}
return reply;
}
//如果传入的参数对象不是表单对象,通常应该是与领域对象对应js对象
else {
//遍历对象属性,将与属性对应的页面元素值拷到js对象中
for (var property in data) {
// Are there any elements with that id or name
if ($(property) != null || document.getElementsByName(property).length >= 1) {
data[property] = DWRUtil.getValue(property);
}
}
return data;
}
};
总结
1)如果你需要使用ajax完成表单提交的操作,那么你应该使用DWRUtil.getValues,参数或者是个form对象,或者是个与领域对象对应的js对象
2)应该看到第二种用法的局限性,如果存在多个相同的表单或者是个复合的js对象,那么第二种用法是不合适的
3)第一种用法看似复杂,但更具灵活性
到底改如何选择取决于具体的应用
原文地址: http://tb.blog.csdn.net/TrackBack.aspx?PostId=847964
【作者: Reg.Lee】【访问统计: 7】【2006年08月24日 星期四 14:52】【 加入博采】【打印】
- 深入分析dwr中的DWRUtil.getValues(转)
- 深入分析dwr中的DWRUtil.getValues
- DWR对象构造,深入分析dwr中的DWRUtil.getValues
- 深入分析dwr中的DWRUtil.$(转)
- 深入分析dwr中的DWRUtil.$
- 用dwr封装表单项提交表单 DWRUtil.getValues()方法一直无效
- DWR小结DWRUtil
- DWR小结DWRUtil
- DWR小结DWRUtil篇
- DWR学习--DWRUtil 使用
- DWR小结之DWRUtil篇
- DWR的DWRUtil.addRows()函数
- DWR小结之DWRUtil篇
- DWR 的方法DWRUtil.addOptions()
- dwr框架中DWRUtil的方法
- DWR DWRUtil.js 内置方法小结
- dwr框架中DWRUtil的方法
- [JavaScript][DWR]DWRUtil.addOptions() 方法详解
- 马上11.4号了
- 对LR回放中highest severity level was"ERROR"的第二个解决方法
- ORACLE索引总结
- 深入分析dwr中的DWRUtil.$(转)
- RSS阅读器制作之拖放操作的实现
- 深入分析dwr中的DWRUtil.getValues(转)
- 总结ecplise3.2下的GUI编程和JSP开发插件的安装配置
- IE7安装:微软一直在监视我们
- 天下有贼
- Visual Studio Team Edition for Database Professionals
- 走动式管理
- 第一个用ASP.NET做的网站---图书管理系统
- Openssl常用基础命令
- 人力资源主管的素质要求