How can I load in a bootbox a custom element with javascript methods attached?

China☆狼群 提交于 2019-12-11 06:59:05

问题


I want to use crop and resize images inside a bootbox. To achieve this, I use Cropper.

Based on the examples of Cropper, I should instantiate the cropper object in my bootbox when it is displayed and get rid of it when it is closed.

Is it possible or should I use a regular bootstrap modal?

Could I, for instance, add a script tag in the bootbox message in order to do the job there? That would be dirty, and before I commit into this, I wanted to check for more clean/elegant approaches.


回答1:


My pattern for using bootbox custom dialogs is to write:

message: "<div id='dialogAnchor'></div>"

in the bootbox dialog definition and follow that up (after you create the bootbox) with

Blaze.render(Template.myDialog,$("#dialogAnchor")[0])

to embed my template into the bootbox dialog directly. This makes managing the contents of the bootbox much, much simpler. I haven't used cropper but assuming you can use it in a normal template then you can use the aforementioned pattern to get that template into a bootbox.



来源:https://stackoverflow.com/questions/31009437/how-can-i-load-in-a-bootbox-a-custom-element-with-javascript-methods-attached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!