猿问

未指定项目 - 带有动态项目的上下文菜单

我有一个简单的页面,它使用数据表显示呼叫中心队列,并使用上下文菜单(委托给此数据表)我想指定呼叫中心代理来呼叫队列中的呼叫。然而,问题是当右键单击控制台日志时显示“未指定项目”。是的,他们是......有人可以帮我看看我在哪里犯了致命错误......?


来自 ActiveList 的数据是一个 JSON 结果(数组),仅包含 { "Agent": "Mario" } 等。我已经尝试将 ri.agent 分配给结果,但这不起作用。


   // Call the dataTables jQuery plugin - SQL Server Wachtrij view.


   $(document).ready(function() {

   var table =  $('#dataTable').dataTable(

   {

    "bPaginate": false,

    "bFilter": false,

    "bInfo": false,

    "bProcessing": false,

    "sAjaxSource": "wachtrij.php",

    "aoColumns": [

          { mData: 'callcenter' } ,

          { mData: 'Tijdstip_binnengekomen' },

          { mData: 'Wachttijd'},

          { mData: 'telefoonnummer'},

          { mData: 'Wachtrij_Positie'},

          { mData: 'callid'},

              {"defaultContent":'<button 

class="btn">Toewijzen aan Agent</button>'}

        ],    

        })


// Make sure dataTable refreshes every 5 seconds 


setInterval( function () {

    table.api().ajax.reload();

}, 5000 );


$.contextMenu({

selector: '#dataTable td',

trigger: 'right',

build: function ($trigger, e)

{

    // check if the menu-items have been saved in the previous call

    if ($trigger.data("contextMenuItems") != null)

    {

        // get options from $trigger

        var options = $trigger.data("contextMenuItems");


        // clear $trigger.data("contextMenuItems"),

        // so that menuitems are gotten next time user does a rightclick 

        // from the server again.

        $trigger.data("contextMenuItems", null);

        return options;

    }

    else

    {

        var options = {

            callback: function (key)

            {

                alert(key);

            },

            items: {}

        };

        $.ajax({

            method: "GET",

            url: "ActiveList.php",

            "aoColumns": [

          { aData: 'agent' }

        ],


慕桂英3389331
浏览 130回答 1
1回答

胡子哥哥

尝试了另一种对我有用的方法。我想我可以在调用 ContextMenu 之前创建一个数组,并在函数本身中使用它,而不是使用“Build”。奇迹般有效。稍后将添加使用表刷新代理列表。&nbsp;// Call the dataTables jQuery plugin - SQL Server Wachtrij view.&nbsp; $(document).ready(function() {&nbsp; var table =&nbsp; $('#dataTable').dataTable(&nbsp; {&nbsp; &nbsp; "bPaginate": false,&nbsp; &nbsp; "bFilter": false,&nbsp; &nbsp; "bInfo": false,&nbsp; &nbsp; "bProcessing": false,&nbsp; &nbsp; "sAjaxSource": "wachtrij.php",&nbsp; &nbsp; "aoColumns": [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { mData: 'callcenter' } ,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { mData: 'Tijdstip_binnengekomen' },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { mData: 'Wachttijd'},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { mData: 'telefoonnummer'},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { mData: 'Wachtrij_Positie'},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { mData: 'callid'}&nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp;// Make sure dataTable refreshes every 5 seconds&nbsp;setInterval( function () {&nbsp; &nbsp; &nbsp; &nbsp; table.api().ajax.reload();&nbsp; &nbsp; }, 5000 );&nbsp;$(function(){// Get agentdata from servervar request = new XMLHttpRequest()request.open('GET', 'ActiveList.php', true)request.onload = function() {var data = JSON.parse(this.response)// create array from http call&nbsp;var menuitems = [];$.each(data, function( key, value ) {&nbsp; &nbsp;menuitems[key] =&nbsp; { name: value.agent, icon: "checkmark", onclick: function () {&nbsp;RToTb(array_name) }};});//create the contextmenu using the array as menuitems$.contextMenu({selector: '#dataTable td',trigger: 'left',items: menuitems&nbsp; });&nbsp; }//Send the request&nbsp; request.send()&nbsp; &nbsp;&nbsp;&nbsp; });&nbsp;});
随时随地看视频慕课网APP
我要回答