jQuery回调函数中的Typescript代码
我想将typescript代码放入jQuery回调函数中。这是一个角度为6分量的ts文件。我使用MaterialDataTable作为HTML模板。当我单击一个按钮时,我想首先让行淡出,然后更新mongoDB,然后重新为我的datatable编页码 现在在这个序列中,淡出不能正常工作,因为update函数不在jQuery的回调函数中(我猜) 谁能帮我弄点光吗 ThxjQuery回调函数中的Typescript代码,jquery,angular,typescript,angular-material,Jquery,Angular,Typescript,Angular Material,我想将typescript代码放入jQuery回调函数中。这是一个角度为6分量的ts文件。我使用MaterialDataTable作为HTML模板。当我单击一个按钮时,我想首先让行淡出,然后更新mongoDB,然后重新为我的datatable编页码 现在在这个序列中,淡出不能正常工作,因为update函数不在jQuery的回调函数中(我猜) 谁能帮我弄点光吗 Thx onSetOK(用户:用户,i:number){ const index=this.dataSource.data.indexO
onSetOK(用户:用户,i:number){
const index=this.dataSource.data.indexOf(用户);
控制台日志(索引);
//这里开始jQuery代码,让行逐渐消失
$().ready(函数()){
const$row=$(“#row”+i);
$row.fadeOut(1000,功能(e){
$row.remove();
//把下面的打字脚本代码放在这里
});
});
//类型脚本代码,更新mongoDB
this.service.updateUserOK(用户).subscribe(res=>{
this.dataSource.data.splice(索引,1);
this.dataSource.sort=this.sort;
this.dataSource.paginator=this.paginator;
});
}
。。。
行动
您错误地使用了就绪功能。引用jQuery API文档:
描述:指定DOM完全加载时要执行的函数
因为此时DOM已完全加载,所以永远不会调用回调。只需执行以下淡入淡出效果:
onSetOK(user: USER, i: number) {
const index = this.dataSource.data.indexOf(user);
console.log(index);
//here begins the jQuery code to let the row fadeout
const $row = $('#row' + i);
$row.fadeOut(1000, (e) => {
$row.remove();
// put the below typescript code here
//typescript code, update mongoDB
this.service.updateUserOK(user).subscribe(res => {
this.dataSource.data.splice(index, 1);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
});
});
}