[英]JavaScript External files dependency in kendo ui grid
I have Two file KendoUIGridFeatures.js & orgs.js which i include in .html page as show below 我有两个文件KendoUIGridFeatures.js和orgs.js,它们包含在.html页面中,如下所示
<script src="Scripts/KendoUIGridFeatures.js"></script>
<script src="Scripts/Orgs.js"></script>
I get the following error when loading html page 加载html页面时出现以下错误
Uncaught ReferenceError: hideColumn is not defined Orgs.js:201
Why am i getting this Error ? 为什么会出现此错误?
If i look into console of google chrome, i see that files were loaded in order and there were no error except the one mentioned above //console output 如果我查看google chrome的控制台,我会看到文件已按顺序加载,除了上面提到的一个//控制台输出,没有错误。
KendoUIGridFetaures Loaded KendoUIGridFeatures.js:3
Orgs Loaded Orgs.js:3
//KendoUIGridFeatures.js
$(document).ready(function () {
console.log("KendoUIGridFetaures Loaded");
var gridFeaturesLoaded = true;
function hideColumn(e) {
}
function showColumn(e) {
}
function columnResize(e) {
}
function reOrderColumn(e) {
}
function gridDatabound(e) {
}
}
//orgs.js
$(document).ready(function () {
console.log("Orgs Loaded");
$("#" + gridName).kendoGrid({
dataSource: dsOrg,
autoBind: false,
columnHide: hideColumn,
columnShow: showColumn,
columnResize: columnResize,
columnReorder: reOrderColumn,
dataBound: gridDatabound,
..........................
});
});
I think your problem is that you are using the function hideColumn
as a global function, but you have not defined it globally. 我认为您的问题是您将函数hideColumn
用作全局函数,但尚未全局定义。
When you define a function in $(document).ready
, that function is only accessible in that scope. 在$(document).ready
定义函数时,只能在该范围内访问该函数。 So you have to move hideColumn
(as well as all your other grid functions) out of the $(document).ready
for it to be accessible. 因此,您必须将hideColumn
(以及所有其他网格功能)移出$(document).ready
以便对其进行访问。
In KendoUIGridFeatures.js you want to move your functions out like this: 在KendoUIGridFeatures.js中,您要像这样将函数移出:
function hideColumn(e) {}
function showColumn(e) {}
function columnResize(e) {}
function reOrderColumn(e) {}
function gridDatabound(e) {}
//add your other grid functions...
$(document).ready(function () {
console.log("KendoUIGridFetaures Loaded");
var gridFeaturesLoaded = true;
//other code you might have...
});
Alternatively, you can also put those functions inside the $(document).ready
of org.js , and it will work since you are calling the function inside the same scope. 另外,您也可以将这些函数放在org.js的$(document).ready
内,由于您在同一作用域内调用该函数,因此它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.