Jquery jtable jtable子表未过帐键值

Jquery jtable jtable子表未过帐键值,jquery-jtable,Jquery Jtable,我有一个Jquery jtable,它有一个子表。据我所知,它是根据jtable演示中的示例设置的。主表=(联系人)和子表(类别)显示没有任何问题。我的问题是category子表上的delete操作没有像我预期的那样发布行键值(categoryID),我看不出为什么没有。在主表上的类似操作显示了它的良好性能。注意下面代码中输出postData变量的两行console.log,第一行报告联系人表行(ID)的ID,但第二行打印空数组而不是CategoryID。谢谢你的帮助 谢谢 function R

我有一个Jquery jtable,它有一个子表。据我所知,它是根据jtable演示中的示例设置的。主表=(联系人)和子表(类别)显示没有任何问题。我的问题是category子表上的delete操作没有像我预期的那样发布行键值(categoryID),我看不出为什么没有。在主表上的类似操作显示了它的良好性能。注意下面代码中输出postData变量的两行console.log,第一行报告联系人表行(ID)的ID,但第二行打印空数组而不是CategoryID。谢谢你的帮助

谢谢

function ReturnAjax(theurl, postdata, errorfn) {
    return $.ajax({
        url: theurl,
        type: 'POST',
        dataType: 'json',
        data: postdata,
        cache: false,
        error: errorfn
    });             
}

    $('#ContactsTableContainer').jtable({
    title: 'Contacts',
    paging: true,
    pageSize: 30,
    sorting: true,
    defaultSorting: 'LastName ASC',
    selecting: true,
    selectOnRowClick: true,
    openChildAsAccordion: true,
    deleteConfirmation: false,
    actions: {
        listAction: function(postData, jtParams) {
            console.log("ContactsTableContainer - Loading list from custom function...");
            return $.Deferred(function($dfd) {
                $.ajax({
                    url: 'ContactsData.php?action=list&jtStartIndex=' + jtParams.jtStartIndex + '&jtPageSize=' + jtParams.jtPageSize + '&jtSorting=' + jtParams.jtSorting,
                    type: 'POST',
                    dataType: 'json',
                    data: postData,
                    success: function(data) {
                        if(data['RowIDs']) { RowIDs = data['RowIDs'].toString().split(','); }
                        $dfd.resolve(data);
                    },
                    error: MyError
                });
            });
        },
        deleteAction: function(postData) {
            console.log('deleting from contacts - custom function..., '+JSON.stringify(postData));
            $.when(
                ReturnAjax(
                    'ContactsData.php?action=list&ContactID='+postData['ID'],
                    postData,
                    MyError
                )
            ).then(
                function(data) {
                    if (data.Result != 'OK') { alert(data.Message); }
                    var msg = '';
                    var len = data.Records.length;
                    if(len>0) {
                        msg = '\t'+data.Records[0].Category;
                        for(var i=1 ; i<len ; i++) { msg += '\n\t'+data.Records[i].Category; }
                        msg = 'Contact is in the following categories\n'+msg;
                    }
                    msg += '\n\nConfirm deletion of this contact';
                    if(confirm(msg)) {
                        $.when(
                            ReturnAjax(
                                'ContactsData.php?action=delete',
                                postData,
                                MyError
                            )
                        ).done(
                            $('#ContactsTableContainer').jtable('reload')
                        );
                    } else {
                        $('#ContactsTableContainer').jtable('reload'); // Had to put this here to ensure that same delete button could be used again
                    }       
                }
            ).fail( function() { console.log('ajax call went wrong'); } );
        }, // end of delete action
    }, // end of actions
    fields: {
        ID: {
            key: true,
            create: false,
            edit: false,
            list: false,
            visibility: 'hidden'
        },
        Categories: {
            title: '',
            width: '5%',
            sorting: false,
            create: false,
            display: function(contact) {
                var $img = $('<img src="Images/layers.png" title="Show contact\'s categories" />');
                //Open child table when user clicks the image
                $img.click(function() {
                    console.log('display function (contact)..., '+JSON.stringify(contact));
                    $('#ContactsTableContainer').jtable(
                        'openChildTable',
                        $img.closest('tr'), //Parent row
                        {
                            title: contact.record.Name + ' - Categories',
                            selecting: true,
                            selectOnRowClick: true,
                            actions: {
                                listAction: 'ContactsData.php?action=list&ContactID=' + contact.record.ID,
                                deleteAction: function(postData) {
                                    console.log('deleting from custom category function..., '+JSON.stringify(postData));
                                    $.when(
                                        ReturnAjax(
                                            'ContactsData.php?action=deleteAssignment&ContactID=' + contact.record.ID,
                                            postData,
                                            MyError
                                        )
                                    ).done(
                                        $('#ContactsTableContainer').jtable('reload')
                                    );
                                }
                            },
                            fields: {
                                CategoryID: { key: true, create: false, edit: false, list: false, visibility: 'hidden' },
                                ContactID: { type: 'hidden', defaultValue: contact.record.ID },
                                Category: { title: 'Category' }
                            }
                        },
                        function(data) { data.childTable.jtable('load'); }
                    );
                });
                //Return image to show on the person row
                return $img;
            }
        },
        FirstName: {
            title: 'Forename',
            width: '25%',
        },
        LastName: {
            title: 'Surname',
            width: '25%',
        },
        HomePhone: {
            title: 'Phone',
            width: '15%',
            sorting: false,
        },
        Mobile: {
            title: 'Mobile',
            width: '15%',
            sorting: false,
        },
        Email: {
            title: 'Email',
            width: '20%',
            sorting: false,
        },
        Name: {
            type: 'hidden'
        },
    }
});

//Load list from server
$('#ContactsTableContainer').jtable('load');
函数返回ajax(url、postdata、errorfn){
返回$.ajax({
url:theurl,
键入:“POST”,
数据类型:“json”,
数据:postdata,
cache:false,
错误:errorfn
});             
}
$(“#ContactsTableContainer”).jtable({
标题:“联系人”,
是的,
页面大小:30,
排序:对,
defaultSorting:'LastName ASC',
选择:对,
selectOnRowClick:true,
openChildAsAccordion:对,
删除确认:错误,
行动:{
listAction:函数(postData、jtParams){
log(“ContactsTableContainer-从自定义函数加载列表…”);
返回$.Deferred(函数($dfd){
$.ajax({
url:'ContactsData.php?action=list&jtStartIndex='+jtParams.jtStartIndex+'&jtPageSize='+jtParams.jtPageSize+'&jtSorting='+jtParams.jtstoring,
键入:“POST”,
数据类型:“json”,
数据:postData,
成功:功能(数据){
if(data['RowIDs']){RowIDs=data['RowIDs'].toString().split(',');}
$dfd.resolve(数据);
},
错误:MyError
});
});
},
deleteAction:函数(postData){
log('deleting from contacts-custom function…,'+JSON.stringify(postData));
美元。什么时候(
ReturnAjax(
'ContactsData.php?action=list&ContactID='+postData['ID'],
postData,
迈罗
)
).那么(
功能(数据){
if(data.Result!=“OK”){alert(data.Message);}
var msg='';
var len=data.Records.length;
如果(len>0){
msg='\t'+数据。记录[0]。类别;

对于(var i=1;i好的,我解决了这个问题,很抱歉打扰了那些可能花时间研究这个问题的人。问题是我的子表变量名错了,它们应该是category\u ID和Contact\u ID