-1
ボタンのクリックイベントに基づいてデータの行を取得しようとしています。行を見つけて結果をテキストとして読み込むことができますが、データキャストを文字列またはオブジェクトとして使用したいと思います。私の現在のコードは以下の通りです:Jquery Datatablesは、ボタンクリック時に行データを文字列またはオブジェクトとして取得します。
$.ajax({
url: "SympsService.asmx/GetSymptoms",
method: "post",
dataType: "json",
data: JSON.stringify({
organ_name: "toes"
}),
contentType: "application/json",
success: function(data) {
var sympList = 'GetSymptoms' ? JSON.parse(data.d) : data.d;
createDataTable('#symptomsTable', sympList);
function createDataTable(target, data) {
$(target).DataTable({
destroy: true,
paging: false,
searching: false,
info: false,
data: data,
columnDefs: [{
targets: [-1],
render: function() {
return "<button type='button'>" + ('Choose') + "</button>"
}
}],
columns: [{
'data': 'Sympt',
'title': 'toes Symptoms'
}, {
'data': null,
'title': 'Action'
}]
});
}
$('#symptomsTable').on("click", "tbody button", function() {
var id = $(this).closest("tr").find("td:nth-child(1)").text(); //this show perfectly
var id = $(this).closest("tr").find("td:nth-child(1)").data(); //this show undefined
var id = $(this).closest("tr").find("td:nth-child(1)").toString(); //this show {object Object}
console.log(id);
})
},
});
何か助けていただければ幸いです。ありがとうございました。
$("#symptomsTable").DataTable().cells($(this).closest("td").siblings().eq(0)).data()
私が試したが、それは捕捉されない例外TypeErrorを示しています:
は、特定のセルのためにそれを見つけるために: –
DataTableをDataTableに変更します。私はちょっとdを取得し、エラーも – Bindrid
私はそれを変更します。しかし、これを表示する:[context:Array [1]、selector:Object、ajax:Object]両方の。 (0))data()何がg [0]にあるか? –