Infragistics igGrid Uncatch TypeError: undefined 不是一个函数

Infragistics igGrid Uncaught TypeError: undefined is not a function

本文关键字:函数 一个 Uncatch igGrid TypeError undefined Infragistics      更新时间:2023-09-26

你好,我在带有Infragistics Grid的Javascript中有一个错误。

当我$("#grid").igGrid放入$.getJSON时,出现此错误:

捕获的类型错误:未定义不是函数

<script type="text/javascript">
    function getHU() {
        var hu = document.getElementById("IP").value;
        var param = location.search.split('q=')[1]
        var url = '/Home/ListContactJson/?q=' + hu;
        getDos(url);  
    }
    function getDos(url) {
        $.getJSON(url, function (q) {
        // Grid
            $("#grid").igGrid({
                width: "100%",
                dataSource: q,
                autoGenerateColumns: false,
                columns: [{
                    key: "LASTNAME",
                    headerText: "LASTNAME",
                    width: "33.33%"
                }],
                features: [{
                    name: "Sorting",
                    columnSettings: [{
                        columnKey: "LASTNAME",
                        currentSortDirection: "descending"
                    }]
                }]
            });
        });
    }
</script>

尝试使用不同版本的 IgniteUI 或 jQuery 并查看结果。这可能有助于诊断问题。

我删除了代码中的一些元素,它可以工作,但没有这段代码:

$( ".link" ).click(function() {});

我想调用此代码,当我单击我的按钮 .link 时,但它不起作用,我遇到了与第一篇文章相同的错误。

<script type="text/javascript">
        $(".link").click(function() {
           var hu = document.getElementById("IP").value;
           var param = location.search.split('q=')[1]
           var url = '/Home/ListContactJson/?q=jean';
            $.getJSON(url, function (q) {
                // Grid
              $("#grid").igGrid({
                    width: "100%",
                    dataSource: q,
                    autoGenerateColumns: false,
                    columns: [{
                        key: "LASTNAME",
                        headerText: "LASTNAME",
                        width: "33.33%"
                    }],
                    features: [{
                        name: "Sorting",
                        columnSettings: [{
                            columnKey: "LASTNAME",
                            currentSortDirection: "descending"
                        }]
                    }]
                });
            });
        });
</script>

错误来自以下事实:location属于全局对象window,一旦进入click事件处理程序,处理程序的上下文就不再是全局上下文,因此location是一个未定义的局部变量。错误来自那里,而不是来自igGrid代码。将您的代码更改为以下内容,一切应该可以正常工作。

var param = window.location.search.split('q=')[1];