Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.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 TypeError:无法设置属性';treeGrid';空的_Javascript_Jquery_Ruby On Rails - Fatal编程技术网

Javascript TypeError:无法设置属性';treeGrid';空的

Javascript TypeError:无法设置属性';treeGrid';空的,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,我正在使用jqxTreeGrid小部件,并遇到TypeError:无法将属性'treeGrid'设置为nullerror 我遇到一些消息来源说,没有找到表所附加到的div,但是我console.log找到了该div 还有什么其他建议可能导致此问题 VIEW <div id="treeGrid"></div> SCRIPT var tableDiv = $("#treeGrid"); var tableData = <%=raw @array_with_d

我正在使用jqxTreeGrid小部件,并遇到
TypeError:无法将属性'treeGrid'设置为null
error

我遇到一些消息来源说,没有找到表所附加到的div,但是我
console.log
找到了该div

还有什么其他建议可能导致此问题

VIEW
<div id="treeGrid"></div>


SCRIPT
var tableDiv = $("#treeGrid");
    var tableData = <%=raw @array_with_data.to_json%>;
    var treeSource, treeData;

    treeSource = {
        dataType: "json",
        dataFields: [
            { name: "id", type: "number" },
            { name: "foo_id", type: "number" },
            { name: "foo_name", type: "string" },
            { name: "bar_id", type: "number" },
            { name: "bar_name", type: "string" },
            { name: "noob_name", type: "string" }
        ],
        hierarchy: {
            keyDataField: { name: "id" },
            parentDataField: { name: "foo_id" }
        },
        id: "id",
        localData: tableData
    };

    treeData = new $.jqx.dataAdapter(treeSource);
    treeData.dataBind();

    // build table as a tree table:
    tableDiv.jqxTreeGrid({
        width: "100%",
        source: treeData,
        sortable: true,
        filterable: true,
        pageable: true,
        selectionMode: "singleRow",
        columns: [
            { text: "ID", dataField: "id", hidden: true },
            { text: "Foo ID", dataField: "foo_id", columnGroup: "foo", width: "20%" },
            { text: "Foo Name", dataField: "foo_name", columnGroup: "foo", width: "20%" },
            { text: "Bar ID", dataField: "bar_id", columnGroup: "bar", width: "20%" },
            { text: "Bar Name", dataField: "bar_name", columnGroup: "bar", width: "20%" },
            { text: "Noob Name", dataField: "noob_name", columnGroup: "noob", width: "20%" }
        ],
        columnGroups: [
            { text: "Foo", name: "foo" },
            { text: "Bar", name: "bar" },
            { text: "Noob", name: "noob" }
        ]
    });
视图
剧本
var tableDiv=$(“#treeGrid”);
var tableData=;
var treeSource,treeData;
树资源={
数据类型:“json”,
数据字段:[
{name:“id”,键入:“number”},
{名称:“foo_id”,类型:“number”},
{name:“foo_name”,键入:“string”},
{name:“bar_id”,键入:“number”},
{name:“bar_name”,键入:“string”},
{name:“noob_name”,键入:“string”}
],
层次结构:{
keyDataField:{name:“id”},
parentDataField:{name:“foo_id”}
},
id:“id”,
localData:tableData
};
treeData=new$.jqx.dataAdapter(treeSource);
treeData.dataBind();
//将表生成为树表:
tableDiv.jqxTreeGrid({
宽度:“100%”,
资料来源:treeData,
可排序:是的,
可过滤:正确,
pageable:对,
selectionMode:“单行”,
栏目:[
{文本:“ID”,数据字段:“ID”,隐藏:true},
{文本:“Foo ID”,数据字段:“Foo_ID”,列组:“Foo”,宽度:“20%”,
{文本:“Foo Name”,数据字段:“Foo_Name”,列组:“Foo”,宽度:“20%”,
{文本:“条ID”,数据字段:“条ID”,列组:“条”,宽度:“20%”,
{文本:“条形图名称”,数据字段:“条形图名称”,列组:“条形图”,宽度:“20%”,
{文本:“Noob Name”,数据字段:“Noob_Name”,列组:“Noob”,宽度:“20%”
],
专栏组:[
{文本:“Foo”,名称:“Foo”},
{文本:“Bar”,名称:“Bar”},
{文本:“Noob”,名称:“Noob”}
]
});

我也有同样的问题

我的问题是,我在jqxtreegrid.js之后包含了jqxdatatable.js

错:

<script type="text/javascript" src="/js/jqwidgets/jqxtreegrid.js"></script>  
<script type="text/javascript" src="/js/jqwidgets/jqxdatatable.js"></script> 

正确:

<script type="text/javascript" src="/js/jqwidgets/jqxdatatable.js"></script>  
<script type="text/javascript" src="/js/jqwidgets/jqxtreegrid.js"></script>


当我把它放在另一个include之前时,它工作了

,这意味着如果您将控制台日志放在代码之前,它就工作了?数据作为有效的javascript变量打印到页面上?如果我放置
console.log(tableDiv.text())
就在
tableDiv.jqxTreeGrid({
并在所述div中放置一些文本…然后文本出现在控制台中。将检查插件的问题跟踪器