简体   繁体   English

jqGrid - TypeError:“#List”.jqGrid不是函数

[英]jqGrid - TypeError: “#List”.jqGrid is not a function

I have the following code in a separate script file in my project for populating jqGrid. 我在我的项目中的单独脚本文件中有以下代码,用于填充jqGrid。

jQuery(document).ready(function () {
    ("#List").jqGrid({
    url: '/Dept/Index/',
    datatype: 'json',
    mtype: 'POST',
    colNames: ['Name'],
    colModel: [{ name: 'Name', index: 'Name', width: 300, align: 'left'}],
    pager: jQuery('#pager'),
    rowNum: 10,
    rowList: [5, 10, 20, 50],
    sortname: 'Id',
    sortOrder: "desc",
    viewrecords: true,
    caption: 'Dept List'
    });
});

When I run the project, I observe the following error in Firebug's console. 当我运行项目时,我在Firebug的控制台中观察到以下错误。 TypeError: "#List".jqGrid is not a function . TypeError: "#List".jqGrid is not a function

If I however embed the script within a file, the error disappears. 但是,如果我将脚本嵌入文件中,则错误消失。 I have followed the instructions on how to install and also looked at answers to similar errors and I am certain that I have jqgrid.js and grid.locale-en.js in the proper order. 我已经按照如何安装的说明进行操作,并查看了类似错误的答案,我确信我的jqgrid.js和grid.locale-en.js的顺序正确。

How can I eliminate this error? 如何消除此错误?

You should use: 你应该使用:

$("#List")

or: 要么:

jQuery("#List")

You can read about it here: 你可以在这里读到它:

http://api.jquery.com/jQuery/ http://api.jquery.com/jQuery/

The result of ("#List") is just a String, which is why the interpreter claims there is no method called jqGrid . ("#List")的结果只是一个字符串,这就是解释器声称没有名为jqGrid方法的jqGrid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM