Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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 未指定项-包含动态项的上下文菜单_Javascript_Php_Jquery_Json - Fatal编程技术网

Javascript 未指定项-包含动态项的上下文菜单

Javascript 未指定项-包含动态项的上下文菜单,javascript,php,jquery,json,Javascript,Php,Jquery,Json,我有一个简单的页面,其中显示了使用datatables的呼叫中心队列,并使用contextmenu(委托给此datatable),我希望为队列中的呼叫指定呼叫中心代理。到目前为止,在So的帮助下,我想到的一切都很有效。但问题是,右键单击控制台日志时显示“未指定任何项”。是的,他们是。。。有人能帮我指出我犯了致命错误的地方吗 ActiveList中的数据是一个JSON结果(数组),只包含{“Agent”:“Mario”}等。我已经尝试将ri.Agent分配给结果,但没有成功 // Call

我有一个简单的页面,其中显示了使用datatables的呼叫中心队列,并使用contextmenu(委托给此datatable),我希望为队列中的呼叫指定呼叫中心代理。到目前为止,在So的帮助下,我想到的一切都很有效。但问题是,右键单击控制台日志时显示“未指定任何项”。是的,他们是。。。有人能帮我指出我犯了致命错误的地方吗

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' }
        ],
        success: function (response, status, xhr)
            {
                // for each menu-item returned from the server
                for (var i = 0; i < response.length; i++)
                {
                    var ri = response[i];
                    // save the menu-item from the server in the 
options.items object
                    options.items[ri.id] = ri;
                }
                // save the options on the table-row;
                $trigger.data("contextMenuItems", options);

                // open the context-menu (reopen)
                $trigger.contextMenu();
            },
            error: function (response, status, xhr)
            {
                if (xhr instanceof Error)
                {
                    alert(xhr);
                }
                else
                {

alert($($.parseHTML(response.responseText)).find("h2").text());
                }
            }
        });
        // This return false here is important                
        return false;
    }
   }

 });

});
//调用dataTables jQuery插件-SQL Server Wachtrij视图。
$(文档).ready(函数(){
变量表=$('#dataTable')。dataTable(
{
“bPaginate”:错误,
“bFilter”:错误,
“bInfo”:假,
“b处理”:false,
“sAjaxSource”:“wachtrij.php”,
“aoColumns”:[
{mData:'呼叫中心'},
{mData:'Tijdstip_binnengekomen'},
{mData:'Wachttijd'},
{mData:'telefoonnummer'},
{mData:'Wachtrij_Positie'},
{mData:'callid'},
{“defaultContent”:“Toewijzen aan代理”}
],    
})
//确保dataTable每5秒刷新一次
setInterval(函数(){
table.api().ajax.reload();
}, 5000 );
$.contextMenu({
选择器:“#数据表td”,
触发器:“对”,
构建:函数($trigger,e)
{
//检查上一次通话中是否保存了菜单项
if($trigger.data(“contextMenuItems”)!=null)
{
//从$trigger获取选项
var options=$trigger.data(“contextMenuItems”);
//清除$trigger.data(“contextMenuItems”),
//这样,下次用户右键单击时将获得菜单项
//再次从服务器上删除。
$trigger.data(“contextMenuItems”,null);
返回选项;
}
其他的
{
变量选项={
回调:函数(键)
{
警报(键);
},
项目:{}
};
$.ajax({
方法:“获取”,
url:“ActiveList.php”,
“aoColumns”:[
{aData:'代理'}
],
成功:功能(响应、状态、xhr)
{
//对于从服务器返回的每个菜单项
对于(变量i=0;i
尝试了另一种适合我的方法。我想我可以在调用ContextMenu并在函数本身中使用它之前创建一个数组,而不是使用“Build”。工作起来很有魅力。稍后将添加使用表刷新代理列表

 // 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'}
        ],    
        })

 // Make sure dataTable refreshes every 5 seconds 

setInterval( function () {
        table.api().ajax.reload();
    }, 5000 );

 $(function(){

// Get agentdata from server

var request = new XMLHttpRequest()

request.open('GET', 'ActiveList.php', true)
request.onload = function() {
var data = JSON.parse(this.response)

// create array from http call 

var menuitems = [];
$.each(data, function( key, value ) {
   menuitems[key] =  { name: value.agent, icon: "checkmark", onclick: function () { 
RToTb(array_name) }};
});

//create the contextmenu using the array as menuitems

$.contextMenu({
selector: '#dataTable td',
trigger: 'left',
items: menuitems
  });

  }
//Send the request

  request.send()    

  });

 });