[英]Delete confirmation - pass data from html when modal popup is opened
I have a delete confirmation popup which is opened on click of delete link. 我有一个删除确认弹出窗口,单击删除链接即可打开。
My HTML: 我的HTML:
<div id="deleteModal">
<p>Are you sure ? </p>
</div>
<ul data-bind="foreach: activList">
<li class="icn add" data-bind="click: function () { $root.deleteFileAsset('Image', $data); }">
<a data-bind="click: function () { $root.deleteImage('Image', $data); }">
<img src="../../CSS/images/DeleteCross.png" />
</a>
<b data-bind="text: title"></b>
</li>
</ul>
In my JS file (as soon as I click on delete, the below method is called): 在我的JS文件中(单击删除后,将立即调用以下方法):
var _deleteImage = function (koList, data) {
window.event.cancelBubble = true;
$('#deleteModal').dialog("open");
}
//Modal popup is opened with the below code which is in ready function
//Ready Function//
$('#deleteModal').dialog({
autoOpen: false,
modal: true,
width: 628.73,
height: 328.38,
buttons: {
'Submit': function () {
_deleteFile(koList, data);
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
//This function is called in the submit click of modal popup
_deleteFile(koList, data)
{
// code for deletion goes here
}
Now what happens here is, 现在发生的是
koList is úndefined'
. koList is úndefined'
。 I need the data and KoList to be passed on confirmation of delete click. 我需要在确认删除点击时传递数据和KoList。 Because that particular data is used in delete method.
因为该特定数据用于删除方法。
You need to store somewhere the data you want to pass, as koList
and data
variables are local. 您需要将要传递的数据存储在某处,因为
koList
和data
变量是局部的。
You could try adding this line in _deleteImage
which uses jQuery to store the data on the DOM node of the modal: 您可以尝试在
_deleteImage
添加此行,该行使用jQuery在模态的DOM节点上存储数据:
$('#deleteModal').data('_tmpData', { koList: koList, data: data });
and modify submit callback: 并修改提交回调:
function () {
var tmpData = $(this).data('_tmpData');
_deleteFile(tmpData.koList, tmpData.data);
$(this).dialog("close");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.