呼叫所有DWR大师!
我目前正在使用反向Ajax向网页中的表格动态添加数据。
当我运行以下方法时:
public static void addRows(String tableBdId, String[][] data) {
Util dwrUtil = new Util(getSessionForPage()); // Get all page sessions
dwrUtil.addRows(tableBdId, data);
}新行将根据需要在我的网页中创建。
但是,为了稍后更新这些新创建的值,标记需要有一个元素ID供我访问。
我已经看过DWR javadoc,您可以指定一些额外的选项参见http://directwebremoting.org/dwr/browser/addRows,但这对我来说意义不大,文档非常稀少。
如果有人能告诉我如何为创建的td元素指定元素id,我将不胜感激。或者,如果有人知道另一种方法,我很想知道。
亲切的问候
卡尔
发布于 2009-05-15 10:59:42
我所能得到的最接近的方法是传入一些参数来给元素一个id。如下所示:
public static void addRows(String tableBdId, String[] data, String rowId) {
Util dwrUtil = new Util(getSessionForPage()); // Get all page sessions
// Create the options, which is needed to add a row ID
String options = "{" +
" rowCreator:function(options) {" +
" var row = document.createElement(\"tr\");" +
" row.setAttribute('id','" + rowId + "'); " +
" return row;" +
" }," +
" cellCreator:function(options) {" +
" var td = document.createElement(\"td\");" +
" return td;" +
" }," +
" escapeHtml:true\"}";
// Wrap the supplied row into an array to match the API
String[][] args1 = new String[][] { data };
dwrUtil.addRows(tableBdId, args1, options);发布于 2015-10-16 01:00:11
您的这行代码真的可以工作吗??
dwrUtil.addRows(tableBdId, data);
要使用,DWR addRows方法至少需要3个参数(共4个),它们是:
id、数组和cellfuncs是所需的,在本例中,您必须传递选项,这也是因为您希望自定义行的创建并设置TD id的E234。看看这个:
在options参数中,您需要使用一个名为"cellCreator“的参数来通知您自己创建td html元素的方法。看看这个:
// Use the cellFuncs var to set the values you want to display inside the table rows
// the syntax is object.property
// use one function(data) for each property you need to show on your table.
var cellFuncs = [
function(data) { return data.name_of_the_first_object_property ,
function(data) { return data.name_of_the_second_object_property; }
];
DWRUtil.addRows(
tableBdId,
data,
cellFuncs,
{
// This function is used for you customize the generated td element
cellCreator:function(options) {
var td = document.createElement("td");
// setting the td element id using the rowIndex
// just implement your own id bellow
td.id = options.rowIndex;
return td;
}
});
https://stackoverflow.com/questions/858734
复制相似问题