我有一个使用ajax输入使用jQuery创建的表。我希望表中的一列允许更新。该表正在创建和填充;但是,“ item.hmpOrder”列无法更新/更改(该列将不接受数据)。
代码是:
$.each(responseJson1a, function(i, item) {
$('<tr>').append(
$('<td>').text(item.hmpId),
$('<td>').text(item.hrId),
$('<td>').text(item.hmId),
$('<td>').text(item.hmName),
$('<td><input type="text"/>').text(item.hmpOrder)
).appendTo('#selectedListTable');
});
答案 0 :(得分:1)
问题出在这一行:
SelectQuery<Record> query = getDslContext().selectQuery();
try {
@Cleanup FileOutputStream fileOutputStream = new FileOutputStream(FILE);
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream);
@Cleanup OutputStreamWriter outputStreamWriter = new OutputStreamWriter(gzipOutputStream, charsetName);
@Cleanup BufferedWriter writer = new BufferedWriter(outputStreamWriter);
@Cleanup Cursor<Record> cursor = query.fetchSize(MAX_FETCH_SIZE).fetchLazy();
while(cursor.hasNext()){
Result<Record> results = cursor.fetchNext(MAX_FETCH_SIZE);
for (Record record : results){
writer.write(record.formatJSON());
writer.newLine();
}
}
您正在尝试一次创建两个元素,而这是您尝试的方式无法实现的。
要解决此问题,请先创建$('<td><input type="text"/>').text(item.hmpOrder)
,然后在单独的操作中为其创建td
append()
,如下所示:
input
var responseJson1a = [{
hmpId: 'hmpId01',
hrId: 'hrId01',
hmId: 'hmId01',
hmName: 'hmName01',
hmpOrder: 'hmpOrder01',
},{
hmpId: 'hmpId02',
hrId: 'hrId02',
hmId: 'hmId02',
hmName: 'hmName02',
hmpOrder: 'hmpOrder02',
}];
$.each(responseJson1a, function(i, item) {
$('<tr>').append(
$('<td>').text(item.hmpId),
$('<td>').text(item.hrId),
$('<td>').text(item.hmId),
$('<td>').text(item.hmName),
$('<td>').text(item.hmpOrder).append('<input type="text" />'),
).appendTo('#selectedListTable');
});
答案 1 :(得分:1)
先在$('<input type="text"/>').val(item.hmpOrder)
中将val放在文本框中。
然后将文本框作为HTML附加到<td>
最终代码:
$.each(response, function(i, item) {
$('<tr>').append(
$('<td>').text(item.hmpId),
$('<td>').text(item.hrId),
$('<td>').text(item.hmId),
$('<td>').text(item.hmName),
$('<td>').append($('<input type="text"/>').val(item.hmpOrder))
).appendTo('#selectedListTable');
});