具有剑道网格事件的外部Javascript文件
是否有从外部Javascript文件读取剑道事件的正确方法 在我看来,.cshtml具有剑道网格事件的外部Javascript文件,javascript,asp.net-mvc-4,kendo-ui,kendo-grid,jquery-events,Javascript,Asp.net Mvc 4,Kendo Ui,Kendo Grid,Jquery Events,是否有从外部Javascript文件读取剑道事件的正确方法 在我看来,.cshtml @(Html.Kendo().Grid<Model>() .Name("EmployeeGrid") .Columns(cols => { }) .Events(evt => evt.DataBound("afterGridLoaded")) .DataSource(dataSourc
@(Html.Kendo().Grid<Model>()
.Name("EmployeeGrid")
.Columns(cols => { })
.Events(evt => evt.DataBound("afterGridLoaded"))
.DataSource(dataSource => dataSource.Ajax()
.Batch(true)
.PageSize(10)
.Read(read => read.Action("GetEmployeeList", "EmployeeDetail"))
)
)
以及Javascript的调用方式——这是在页面顶部完成的
@section scripts
{
<script src="~/Scripts/Views/EmployeeDetail/EmployeeList.js" ></script>
}
@节脚本
{
}
外部Javascript文件已加载,正如我在Chrome中的开发工具的网络选项卡下看到的那样
当我尝试加载页面时,控制台上会出现以下错误消息,阻止页面进一步加载
有没有办法使用外部Javascript文件使剑道事件正常工作?问题在于
afterGridLoaded
函数围绕着jQuery
闭包函数,这意味着不能从闭包外部调用它
移除闭包并将脚本标记移动到页面底部
// $(function () { get rid of this
function afterGridLoaded(e) {
$(".k-button.xxx").click(function () {
debugger;
var idEmployee = $(this).attr('tag');
myJsFunc(idEmployee);
});
}
//}); and this
问题是您的
afterGridLoaded
函数围绕着jQuery
闭包函数,这意味着您不能从闭包外部调用它
移除闭包并将脚本标记移动到页面底部
// $(function () { get rid of this
function afterGridLoaded(e) {
$(".k-button.xxx").click(function () {
debugger;
var idEmployee = $(this).attr('tag');
myJsFunc(idEmployee);
});
}
//}); and this
问题是您的
afterGridLoaded
函数围绕着jQuery
闭包函数,这意味着您不能从闭包外部调用它
移除闭包并将脚本标记移动到页面底部
// $(function () { get rid of this
function afterGridLoaded(e) {
$(".k-button.xxx").click(function () {
debugger;
var idEmployee = $(this).attr('tag');
myJsFunc(idEmployee);
});
}
//}); and this
问题是您的
afterGridLoaded
函数围绕着jQuery
闭包函数,这意味着您不能从闭包外部调用它
移除闭包并将脚本标记移动到页面底部
// $(function () { get rid of this
function afterGridLoaded(e) {
$(".k-button.xxx").click(function () {
debugger;
var idEmployee = $(this).attr('tag');
myJsFunc(idEmployee);
});
}
//}); and this