首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >元素ID为%s的DWR addRows()

元素ID为%s的DWR addRows()
EN

Stack Overflow用户
提问于 2009-05-13 15:46:37
回答 2查看 2.3K关注 0票数 0

呼叫所有DWR大师!

我目前正在使用反向Ajax向网页中的表格动态添加数据。

当我运行以下方法时:

代码语言:javascript
运行
复制
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,我将不胜感激。或者,如果有人知道另一种方法,我很想知道。

亲切的问候

卡尔

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-05-15 10:59:42

我所能得到的最接近的方法是传入一些参数来给元素一个id。如下所示:

代码语言:javascript
运行
复制
    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);
票数 0
EN

Stack Overflow用户

发布于 2015-10-16 01:00:11

您的这行代码真的可以工作吗??

代码语言:javascript
运行
复制
dwrUtil.addRows(tableBdId, data);

要使用,DWR addRows方法至少需要3个参数(共4个),它们是:

  1. id:表格元素的id (最好是包含一个条目的element);
  2. array:数组(或DWR1.1中的对象)更新后的table;
  3. cellfuncs:中的每一行一个函数数组(每列一个),用于从传递的行data;
  4. options:包含各种选项的对象中提取单元格数据。

id数组cellfuncs所需的,在本例中,您必须传递选项,这也是因为您希望自定义行的创建并设置TD id的E234。看看这个:

在options参数中,您需要使用一个名为"cellCreator“的参数来通知您自己创建td html元素的方法。看看这个:

代码语言:javascript
运行
复制
// 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;
					 }
				});		

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/858734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档