Javascript Jtable 单击两次时关闭子表

标签 javascript jquery asp.net-mvc jquery-jtable

我有一个带有一些子表的 Javascript Jtable。我想做的是当第二次单击行标题时关闭子表。

所以我设置了一些全局变量:

var NotesOpen = false;
var HistoryOpen = false;
var ElementsOpen = false;

因此,在 f.ex 上,Notes 子表中的单击函数如下所示:

$img.click(function () {

if (NotesOpen == true) {
   console.log($(this).closest('tr').next('tr').find(':button').html());

   $(this).closest('tr').next('tr').find(':button').click();
   $(this).closest('tr').next('tr').find(':button').trigger('click');
   $(this).closest('tr').next('tr').find('.jtable-close-button').click();
}
NotesOpen = true;

我可以看到调试线。它找到了正确的行,因为它说的是 <span>Close</span>在控制台窗口中。如果我只是检查 $(this).closest('tr').next('tr').html()我可以看到它位于正确的行。

但是,当我尝试触发点击事件时,我只收到错误:Uncaught Error: cannot call methods on jtable prior to initialization; attempted to call method 'destroy' jquery-2.1.1.js:250

最佳答案

此代码有助于通过单击图像图标来打开或关闭子表。

//CHILD TABLE DEFINITION FOR "PHONE NUMBERS"
Phones: {
    title: '',
    width: '5%',
    sorting: false,
    edit: false,
    create: false,
    display: function (studentData) {

        var $img = $('<img src="/Content/images/Misc/phone.png" title="Edit phone numbers" />'), //Create an image that will be used to open child table
            parentTable = $("#StudentTableContainer"); 

        //Open | Close child table when user clicks the image
        $img.click(function(){

            var tr = $(this).parents("tr"),
                isChildRowOpen = parentTable.jtable("isChildRowOpen", tr );

            if( isChildRowOpen ){
                $( parentTable.jtable("getChildRow", tr ) ).slideUp();
                return;
            }

            // some another code
        }
    }
}

关于Javascript Jtable 单击两次时关闭子表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25587121/

相关文章:

javascript - Safari 在缩小窗口时将一个奇怪的对象插入到 DOM 中,这会扰乱 jQuery 的 position() 结果

Jquery 对话框 : content shown before the dialog is open

asp.net-mvc - 参数异常 : Invalid value for key 'integrated security'

javascript - 在 Angular.js 中使用 ngRoute 时出现错误

javascript - node js中buffer.copy()有什么用?

javascript - 简单形式不传递所有变量?

javascript - Ajax 和 Jquery 中的 if else 条件不起作用

javascript - 如果用户使用 Promise,我该如何处理 "check"?

javascript - 如何将 Viewdata 添加到我的 Javascript 中?

c# - 有没有办法从.net MVC中的代码编译scss文件