Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

功能节点中打印功能,按钮打印重复触发调用---click重复绑定 #6

Open
lizhik opened this issue Aug 29, 2016 · 0 comments

Comments

@lizhik
Copy link

lizhik commented Aug 29, 2016

目前我们 功能节点逐渐增加了打印功能,大部分打印按钮设置设计在模态框弹出后显示打印按钮,如下图:
image
在实际测试中发现打印按钮取消再点击打印操作多次后,打印功能被调用多次~

qq 20160829110135

哎呀,中邪还是手抖了~后来按规律测试,点几次按钮,就弹出几次打印页面。代码点击事件如下
$('#ensurePrint').click(function() { $('#depModal').modal('hide'); viewModel.printContent(); });
点击几次,点击事件就会触发几次,于是我怀疑这货不嫌麻烦每次弹窗都给我绑了个事件,那么验证一下:
点击三次,我们从控制台看一下事件监听:
12

果然是这样,编码的时候没有注意到这个问题,
弹窗框每一次弹出事件都会进行了一次绑定,导致多次执行打印的调用,在这里我们可以用采用方法:
1.每次弹出框消失都清除重新添加,不过这种有可能多次操作的,这种方法显然二的不要不要的。
2.选择了先unbind取消绑定,再绑定点击事件,事件就不会多次绑定:
$('#ensurePrint').unbind('click').click(function() { $('#depModal').modal('hide'); viewModel.printContent(); });
以后的点击事件希望大家可以注意此类问题

@lizhik lizhik changed the title 功能节点中打印功能,按钮打印重复触发调用打印 功能节点中打印功能,按钮打印重复触发调用---click重复绑定 Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant