`
congpeixue
  • 浏览: 270305 次
  • 性别: Icon_minigender_1
  • 来自: ...
社区版块
存档分类
最新评论

DWR (编辑Table)

    博客分类:
  • Ajax
阅读更多
创建table

本例子介绍一些在DWR2.0中才出现的特征。
当页面被第一次加载的时候,onload事件将调用服务器端的People.getAllPeople()函数返回一个people对象的数组。

JavaScript使用cloneNode()在表格内为每一个返回的person建立一列。具体来说,对每一个person
引用
dwr.util.cloneNode("pattern", { idSuffix:person.id });
这将建立一个id为pattern节点的copy。

假如原有的node如下:
引用
<div id="pattern"><input id="edit"/></div>
经过上述操作后(假定person.id=42),我们将得到:
引用
<div id="pattern"><input id="edit"/></div>
<div id="pattern42"><input id="edit42"/></div>


之后, 我们使用setValue 为新的克隆的列赋值。
dwr.util.setValue("tableName" + id, person.name);
dwr.util.setValue("tableSalary" + id, person.salary);
dwr.util.setValue("tableAddress" + id, person.address);


我们需要将模式列设置为不可见,克隆列设置为可见, 如此,将需要如下操作
引用
$("pattern" + id).style.display = "table-row";



编辑form

function editClicked(eleid) {
  // we were an id of the form "edit{id}", eg "edit42". We lookup the "42"
  var person = peopleCache[eleid.substring(4)];
  dwr.util.setValues(person);
}


dwr.util.setValues() 用于将为form表单中的各个字段设值。
对于上例来说, 他会将person中的字段与form表单中的名字相同的字段关联起来。

更新服务器


function writePerson() {
  var person = { id:viewed, name:null, address:null, salary:null };
  dwr.util.getValues(person);

  dwr.engine.beginBatch();
  People.setPerson(person);
  fillTable();
  dwr.engine.endBatch();
}


dwr.util.getValues() 用于提交变更到服务器
并且我们使用了batch, 用于确保我们和服务器端仅做了一次交互。
  • DWR.rar (488.2 KB)
  • 下载次数: 77
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics