我有一個 TableEdit 的問題
這是在我閱讀的檔案中:
// Example #2
columns: {
// Column used to identify table row.
// [column_index, input_name]
identifier: [0, 'id'],
// Columns to transform in editable cells.
// [[column_index, input_name], [column_index, input_name, select_options]]
editable: [[1, 'car'], [2, 'color', '{"1": "Red", "2": "Green", "3": "Blue"}']]
}
在可編輯鍵中,第二個陣列包含一個類似 json 的字串,當我按下編輯按鈕時,該字串呈現為下拉串列。
我的問題是,如何動態制作類似 json 的字串?
我有一個回傳部門串列的 ajax 請求。我想將這些部門傳遞到可編輯的列中。
uj5u.com熱心網友回復:
在我看來,您可以嘗試呼叫 ajax request 來獲取部門串列。之后創建tabledit. 你可以這樣試試:
Javascript :
ajax請求完成后。您可以使用JSON.stringify()將 JavaScript 物件轉換為字串。
function initTableEdit() {
$.post('select-data.php')
.done(function (res) {
let data = [[1, 'First Name'], [2, 'Last Name'], [3, 'Username', JSON.stringify(res)]]
creatTableEdit(data)
})
}
function creatTableEdit(data) {
$('#example2').Tabledit({
editButton: true,
removeButton: false,
columns: {
identifier: [0, 'id'],
editable: data
}
});
}
PHP : 選擇-data.php
<?php
header('Content-Type: application/json');
echo json_encode([
1 => '@mdo', 2 => '@fat', 3 => '@twitter',
]);
die();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/391537.html
標籤:javascript 查询 阿贾克斯 平板电脑
