I've looked around for a solution but I might just be missing something really obvious because they don't solve my issue. I am no JS wiz at all, just a disclaimer.

我一直在寻找解决方案,但我可能只是错过了一些非常明显的东西,因为它们没有解决我的问题。我根本不是JS,只是一个免责声明。

I have an ASP project where JavaScript calls some C# code some times. I start my code with this:

我有一个ASP项目,其中JavaScript有时会调用一些C#代码。我用这个开始我的代码:

window.onload = function () {
    LiveSearch();
    getCredentials();
    getAllUsers();
    getIsAdmin();
};

All of these functions work just fine. But the one of interest is getAllUsers() because it contacts the backend via an AJAX call to get some data to fill in a table.

所有这些功能都可以正常工作。但感兴趣的是getAllUsers(),因为它通过AJAX调用联系后端以获取一些数据来填充表。

function getAllUsers() {
    var result_body = "";
    $.ajax({
        type: 'GET',
        url: '/Home/GetAllUsers',
        dataType: 'json',
        cache: false,
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(""),
        success: function (users) {
            PushToScope("users", users);
            var dict = scope[2];
            if (dict.key.length > 0) {
                for (var key in dict.value) {
                    result_body += '<tr onclick="getClickedUserObject(' + dict["value"][key].Initials + ')\">';
                    result_body += '<td class=\"col-xs-4\">' + dict["value"][key].Name + '</td>'
                    result_body += '<td class=\"col-xs-4\">' + dict["value"][key].Title + '</td>'
                    result_body += '<td class=\"col-xs-4\">' + dict["value"][key].Department + '</td>'
                    result_body += '<td style=\"display: none\">' + dict["value"][key].PrivatePhone + '</td>'
                    result_body += '<td style=\"display: none\">' + dict["value"][key].WorkEmail + '</td>'
                    result_body += '<td style=\"display: none\">' + dict["value"][key].WorkPhoneLandline + '</td>'
                    result_body += '<td style=\"display: none\">' + dict["value"][key].WorkPhoneMobile + '</td>'
                    result_body += '</tr>';
                }
            } else {
                result_body += '<tr>';
                result_body += '<td style=\"col-xs-12\"><b>No Data. Try again, or Contact IT Support.</b></td>';
                result_body += '</tr>';
            }
            $('#result-table').html(result_body);
        }
    });
}

Like I said, the above works, but the problem comes forth when I click an element in my table. "getClickedUserObject()" below:

就像我说的,上面的工作,但当我点击我的表中的元素时,问题出现了。下面的“getClickedUserObject()”:

function getClickedUserObject(lettercode) {
    if (lettercode != undefined) {
        var users = scope[2];
        var user = users["value"][lettercode];
        $('#result-title').html(user.Title);
        $('#result-name').html(user.Name);
        $('#result-department').html(user.Department);
        $('#result-email').html('<a href=\"mailto:' + user.WorkEmail + '\">' + work.WorkEmail + '</a>');
        $('#result-work-mobile').html(user.WorkPhoneMobile);
        $('#result-work-landline').html(user.WorkPhoneLandline);
        $('#result-private-mobile').html(user.PrivatePhone);
        if (lettercode == scope[0]) {
            $("#HidePrivate").show();
            $("#HidePrivate").disabled = false;
            $("#HidePrivate").checked = user.HiddenPrivatePhone;
        } else {
            $("#HidePrivate").hide();
            $("#HidePrivate").disabled = true;
        }
    }
    return false;
}

This function never fires, instead I get the error in the title, saying that whatever lettercode I would get from clicking a row is not defined. This is odd to me because looking in the Google Chrome inspector I see this:

这个函数永远不会触发,而是我在标题中得到错误,说没有定义单击行所得到的任何字母代码。这对我来说很奇怪,因为查看Google Chrome检查器我看到了:

So what gives?

什么赋予了什么?

1 个解决方案

#1


2

I'm not familiar with your function, but maybe the argument should be a string? Looks like you don't have any quotes around it in the function call.

我不熟悉你的功能,但也许参数应该是一个字符串?看起来你在函数调用中没有任何引号。

Like so:

result_body += '<tr onclick=\"getClickedUserObject(\'' + dict["value"][key].Initials + '\')\">';

更多相关文章

  1. Webhoster插入了一个javascript,它会阻止我的代码如何删除它?
  2. 可以直接拿来用的15个jQuery代码片段
  3. 如何使用ajax GET或POST方法将数据传递到amazon lambda节点。js
  4. 在each()函数内部调用多个ajax ..然后在完成所有这些操作后执行某
  5. 为什么使用observe_field代码不能使用JQuery模型对话框?
  6. 加载函数加载页面但不能对数据执行任何操作
  7. 绑定和解除相同javascript函数的目的是什么?
  8. Jquery中的队列函数quene()、dequene()、clearQuene()
  9. jquery 生成table表格 部分代码

随机推荐

  1. 用于填充表的倍数ng-repeat
  2. 这些年,我收集的JavaScript代码(二)
  3. 读取json并显示鼠标上的动态值
  4. 浏览器环境下JavaScript脚本加载与执行探
  5. 在单页中使用ajax和php上传多个表单数据
  6. 具有iOS Swift请求时间输出的Express.js
  7. 数组多重排序
  8. jQuery在5秒后自动加载div
  9. 如何在单击按钮时将桌面应用程序导航到系
  10. 如何用NodeJS组织构建、服务器、客户端和