Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jTable如何获取选定行数据_Javascript_Php_Jquery Jtable - Fatal编程技术网

Javascript jTable如何获取选定行数据

Javascript jTable如何获取选定行数据,javascript,php,jquery-jtable,Javascript,Php,Jquery Jtable,如何从jTable中选择的行中获取数据?例如,我单击第一行,所选行的数据进入我的输入框。您可以通过注册事件“selectionChanged”获得所选元素,如下所示 $('#tableName').jtable({ selecting: true, columnResizable: false, actions: { }, fields: { KeyId: {

如何从jTable中选择的行中获取数据?例如,我单击第一行,所选行的数据进入我的输入框。

您可以通过注册事件“selectionChanged”获得所选元素,如下所示

$('#tableName').jtable({
        selecting: true,
        columnResizable: false,
        actions: {
        },
        fields: {
            KeyId: {
                key: true,
                create: false,
                list: false
            },
            Name: {
                title: 'Name',
                sorting: true
            },
            Description: {
                title: 'Description',
                create: false,
                list: false
            },
            StartDate: {
                title: 'Start Date'
            },
            EndDate: {
                title: 'End Date'
            },
            Status: {
                title: 'Status',
                list: false
            }
        },
        //Register to selectionChanged event to handle events
        selectionChanged: function () {
            var $selectedRows = $('#tableName').jtable('selectedRows');
            $selectedRows.each(function () {

                var record = $(this).data('record');
                var keyid = record.KeyId;
                var name = record.Name;

                alert(" KeyId:" + keyid + " Name:" + name);
            });
        }
    });

您可以使用以下代码获取json字符串中的所有表记录数据:

/* Read each record and add it to json */
var $selectedRows = $('#your_table').jtable('selectedRows'),records = [];
$selectedRows.each(function () {
    var record = $(this).data('record');
    records.push(record);
});
var josn_data = JSON.stringify(records);

你能展示你的代码让我们有一些背景吗?