如何将数组中的值填充到表行's文本框

How to fill values in an array in to table row's textboxes

本文关键字:文本 数组 填充      更新时间:2023-09-26

我的代码是这样的-

<table border="0" cellspacing="2" cellpadding="2" width="99%" id="subAccTable">
        <tr>
               <h2>Sub Accounts</h2>
        </tr>
        <tr>
            <th>action </th>
            <th>account</th>
            <th>homeDir</th>
            <th>primaryGroup</th>
        </tr>
    <tr>
        <td><input type="hidden" name="vtierId" value="<%=vtierId%>" /></td>
        <td><input type="text" name="subAcc"
                value="<%= (String)subAccountUtil.getSubAccountName().get(i) %>"/></td>
            <td><input type="text" name="subHomeDir"
                value="<%= (String)subAccountUtil.getSubAccountHomeDir().get(i) %>"/></td>
            <td><input type="text" name="subPriGroup"
                value="<%= (String)subAccountUtil.getSubAccountPrimaryGroup().get(i) %>" /></td>
<script>
                var saveObj = new ajax();
        form.action.value = "populate";
        var queryString = "action="+form.action.value+"&vtierSelectedValue="+vtierSelectedValue+"&vtierSelectedName="+vtierSelectedName ;
        saveObj.onCompletion = function() {
            var obj = saveObj.response;
            alert(obj);
            var objArr = obj.split(",");
            }
             saveObj.form = form;
    saveObj.requestFile = "account.do";
    saveObj.runAJAX(queryString);
</script>

现在,我想用数组objArr中的值填充这里的表行,该数组包含1234、~、tedtds、tedtd等值。如何将此数组中的值填充到表行中的文本框中?目前,文本框从scriptlet中获取我不想要的值?

你应该做的是在数组上循环,我不太清楚objArr中的数据是如何排列的,但下面的代码可以调整

var i = objArr.length, html=[], row, id,inputs ;
while (i--) {
   row = objArr[i].split(";"); //supposing that each contains "id;val1;val2;val3"
   id=row[0] //supposedly
   inputs = $("#" + id + " input");
   $(inputs[0]).val(row[1]);
   $(inputs[1]).val(row[2]);
   $(inputs[2]).val(row[3]);
}