在dwr.util.addRows后,我需要 那个table立的各各控件可以修改,网上找了个例子:3、addRows and removeAllRows 填充表格
DWR 提供2个函数来操作 table;
----------------------------
DWRUtil.addRows(); 添加行
----------------------------
DWRUtil.removeAllRows(id); 删除指定id的table
----------------------------
下面着重看一下 addRows() 函数:
DWRUtil.addRows(id, array, cellfuncs, [options]);
其中id 对应 table 的 id(更适合tbodye,推荐使用 tbodye)
array 是server端服务器的返回值,比如list,map等等
cellfuncs 及用返回值来天春表格
[options] 用来设置表格样式,它有2个内部函数来设置单元格样式(rowCreator、cellCreator)。 比如: server端返回list,而list中存放的是下面这个 bean:
public class Person {
private String name;
private Integer id;
pirvate String address;
public void set(){……}
public String get(){……}
}
下面用 DWRUtil.addRows();
/**************************************************************************************/
/****************** 胡国清***********[email protected]********************************/
/**************************************************************************************/ function userList(data){
//var delButton = "<input type='button'/>";
//var editButton = "<input type='button'/>";
var cellfuncs = [
function(data){return data.id;},
function(data){return data.userName;},
function(data){return data.userTrueName;},
function(data){return data.birthday;},
function(data){
var idd = data.id;
var delButton = document.createElement("<INPUT TYPE='button' ōnclick='delPerson("+ idd +")'>");
delButton.setAttribute("id","delete");
delButton.setAttribute("value","delete");
return delButton;
},
function(data){
var idd = data.id;
var editButton = document.createElement("<INPUT TYPE='button' ōnclick='editPerson("+ idd +")'>");
editButton.setAttribute("name","edit");
editButton.setAttribute("value","edit");
return editButton;
}
];
DWRUtil.removeAllRows('tabId');
DWRUtil.addRows('tabId', data,cellfuncs,{
rowCreator:function(options) {
var row = document.createElement("tr");
var index = options.rowIndex * 50;
row.setAttribute("id",options.rowData.id);
row.style.collapse = "separate";
row.style.color = "rgb(" + index + ",0,0)";
return row;
},
cellCreator:function(options) {
var td = document.createElement("td");
var index = 255 - (options.rowIndex * 50);
//td.style.backgroundColor = "rgb(" + index + ",255,255)";
td.style.backgroundColor = "menu";
td.style.fontWeight = "bold";
td.style.align = "center";
return td;
}
});
document.getElementById("bt").style.display = "none";
}我 争对我的程序做了相应的修改:
<TBODY id="tabId" > </TBODY> loadLastRatePriceData : function (data){ //显示收盘价
dialog.setContentSize(content.getEl().dom.scrollWidth, 400);
var cellfuncs = [
function(data){return data.engName;},
function(data){return data.cenBidDeltaPrice;},
function(data){return data.cenAskDeltaPrice;},
function(data){return data.cenBidMoneyPrice;},
function(data){return data.cenAskMoneyPrice;},
function(data){return data.rateTimeFormat;},
function(data){
var idd = data.engName;
var editButton = document.createElement("<INPUT TYPE='button' onclick='editPerson("+ idd +")'>");
editButton.setAttribute("name","edit");
editButton.setAttribute("value","编辑");
return editButton;
}
];
dwr.util.removeAllRows('tabId');
dwr.util.addRows('tabId', data,cellfuncs,{
rowCreator:function(options) {
var row = document.createElement("tr");
var index = options.rowIndex * 50;
row.setAttribute("id",options.rowData.id);
row.style.collapse = "separate";
row.style.color = "rgb(" + index + ",0,0)";
return row;
},
cellCreator:function(options) {
var td = document.createElement("td");
var index = 255 - (options.rowIndex * 50);
//td.style.backgroundColor = "rgb(" + index + ",255,255)";
td.style.backgroundColor = "menu";
td.style.fontWeight = "bold";
td.style.align = "center";
return td;
}
});
//document.getElementById("lastRatePriceMod").style.display="none";
},TBODY 里的数据 现在可以全部显示出来,但是我 需要 能编辑里面的数据,创建了一个editButton 按钮,
function(data){
var idd = data.engName;
var editButton = document.createElement("<INPUT TYPE='button' onclick='editPerson("+ idd +")'>");
editButton.setAttribute("name","edit");
editButton.setAttribute("value","编辑");
return editButton;
}
onclick 这个事件 editPerson("+ idd +") 这个 是一个什么事件?为什么我点编辑这个按钮,没反应?
editPerson 需不需要 另外 写函数?例子里面为什么没对这个函数进行编辑?
DWR 提供2个函数来操作 table;
----------------------------
DWRUtil.addRows(); 添加行
----------------------------
DWRUtil.removeAllRows(id); 删除指定id的table
----------------------------
下面着重看一下 addRows() 函数:
DWRUtil.addRows(id, array, cellfuncs, [options]);
其中id 对应 table 的 id(更适合tbodye,推荐使用 tbodye)
array 是server端服务器的返回值,比如list,map等等
cellfuncs 及用返回值来天春表格
[options] 用来设置表格样式,它有2个内部函数来设置单元格样式(rowCreator、cellCreator)。 比如: server端返回list,而list中存放的是下面这个 bean:
public class Person {
private String name;
private Integer id;
pirvate String address;
public void set(){……}
public String get(){……}
}
下面用 DWRUtil.addRows();
/**************************************************************************************/
/****************** 胡国清***********[email protected]********************************/
/**************************************************************************************/ function userList(data){
//var delButton = "<input type='button'/>";
//var editButton = "<input type='button'/>";
var cellfuncs = [
function(data){return data.id;},
function(data){return data.userName;},
function(data){return data.userTrueName;},
function(data){return data.birthday;},
function(data){
var idd = data.id;
var delButton = document.createElement("<INPUT TYPE='button' ōnclick='delPerson("+ idd +")'>");
delButton.setAttribute("id","delete");
delButton.setAttribute("value","delete");
return delButton;
},
function(data){
var idd = data.id;
var editButton = document.createElement("<INPUT TYPE='button' ōnclick='editPerson("+ idd +")'>");
editButton.setAttribute("name","edit");
editButton.setAttribute("value","edit");
return editButton;
}
];
DWRUtil.removeAllRows('tabId');
DWRUtil.addRows('tabId', data,cellfuncs,{
rowCreator:function(options) {
var row = document.createElement("tr");
var index = options.rowIndex * 50;
row.setAttribute("id",options.rowData.id);
row.style.collapse = "separate";
row.style.color = "rgb(" + index + ",0,0)";
return row;
},
cellCreator:function(options) {
var td = document.createElement("td");
var index = 255 - (options.rowIndex * 50);
//td.style.backgroundColor = "rgb(" + index + ",255,255)";
td.style.backgroundColor = "menu";
td.style.fontWeight = "bold";
td.style.align = "center";
return td;
}
});
document.getElementById("bt").style.display = "none";
}我 争对我的程序做了相应的修改:
<TBODY id="tabId" > </TBODY> loadLastRatePriceData : function (data){ //显示收盘价
dialog.setContentSize(content.getEl().dom.scrollWidth, 400);
var cellfuncs = [
function(data){return data.engName;},
function(data){return data.cenBidDeltaPrice;},
function(data){return data.cenAskDeltaPrice;},
function(data){return data.cenBidMoneyPrice;},
function(data){return data.cenAskMoneyPrice;},
function(data){return data.rateTimeFormat;},
function(data){
var idd = data.engName;
var editButton = document.createElement("<INPUT TYPE='button' onclick='editPerson("+ idd +")'>");
editButton.setAttribute("name","edit");
editButton.setAttribute("value","编辑");
return editButton;
}
];
dwr.util.removeAllRows('tabId');
dwr.util.addRows('tabId', data,cellfuncs,{
rowCreator:function(options) {
var row = document.createElement("tr");
var index = options.rowIndex * 50;
row.setAttribute("id",options.rowData.id);
row.style.collapse = "separate";
row.style.color = "rgb(" + index + ",0,0)";
return row;
},
cellCreator:function(options) {
var td = document.createElement("td");
var index = 255 - (options.rowIndex * 50);
//td.style.backgroundColor = "rgb(" + index + ",255,255)";
td.style.backgroundColor = "menu";
td.style.fontWeight = "bold";
td.style.align = "center";
return td;
}
});
//document.getElementById("lastRatePriceMod").style.display="none";
},TBODY 里的数据 现在可以全部显示出来,但是我 需要 能编辑里面的数据,创建了一个editButton 按钮,
function(data){
var idd = data.engName;
var editButton = document.createElement("<INPUT TYPE='button' onclick='editPerson("+ idd +")'>");
editButton.setAttribute("name","edit");
editButton.setAttribute("value","编辑");
return editButton;
}
onclick 这个事件 editPerson("+ idd +") 这个 是一个什么事件?为什么我点编辑这个按钮,没反应?
editPerson 需不需要 另外 写函数?例子里面为什么没对这个函数进行编辑?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货