【发布时间】:2016-09-21 12:24:23
【问题描述】:
我一直在为数据表库使用出色的插件 yadcf。我一直在将它用于 asp.net mvc 5 的视图中,没有任何问题。 我们目前正在将应用程序迁移到 Angular 2,并使用 ASP.NET Web Api 提供数据。
我已经以最小的更改移动了代码,并通过将对数据表库的引用放在承载 Angular 应用程序的 index.html 页面上的脚本标记中,设法让数据表正常工作。
然后我从托管表的组件中运行下面的数据表初始化代码。
但是,每当我尝试对 yadcf.init 执行相同操作时,我都会得到:
Uncaught (in promise): TypeError: Cannot read property 'replace' of undefined
然后它崩溃了。
ngOnInit(){
this.table = $('#studyList')
.DataTable({
serverSide: true,
responsive: true,
processing: true,
ajax: {........
........
}
.........
});
// runs fine to here and datatables works when the following is commented out
// but crashes as soon as i try and initialise yadcf from
// from within the component as follows.
yadcf.init(this.table,
[
{
column_number: 5,
filter_type: 'multi_select',
select_type: 'select2',
data: [
{ label: 'Included', value: 1 },
{ label: 'Excluded', value: 2 },
{ label: 'Insufficiently Screened', value: 4 }
]
}
]);
// This causes "Uncaught (in promise): TypeError:
// Cannot read property 'replace' of undefined" error
}
真的不想失去新应用程序中的过滤功能,因此非常感谢您的帮助!
是否有一些关键可以让我使用我缺少的 angular 2?
编辑
看起来错误实际上是由使用 jquery 3 引起的(见下文)。
【问题讨论】:
-
提供一个测试页面的链接,以便调试它
标签: jquery angular datatables yadcf