gpt4 book ai didi

javascript - Knockout js - 确认后从列表中删除项目

转载 作者:行者123 更新时间:2023-11-28 01:35:34 24 4
gpt4 key购买 nike

我正在使用knockout js 和bootstrap。我有一个用户列表,每行都有一个删除按钮。我还有一个 Bootstrap 模式对话框,其中有一条确认消息是否删除用户。我在删除按钮上单击绑定(bind),可以从模型中删除用户。我如何更改它以便在用户确认后删除。我搜索了几个示例,它们都建议使用自定义绑定(bind),我发现的最接近的是这个 fiddle 示例

http://jsfiddle.net/snaptopixel/vDZQk/

此示例的一个问题是,它在模式弹出窗口中使用模型中的预定义项目,我想要的是自动绑定(bind)用户删除的项目并在中显示用户名和其他属性模式窗口并要求确认。

这是我的模式对话框

<div class="modal-body">

<div class="well">
<p>By clicking 'Yes', you will remove the User 'foo' from the system. This action cannot be undone. To cancel this action, click 'No'. </p>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-primary">Yes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>

</div>

例如...

模态窗口将显示“您确定要删除用户“foo”吗?我想访问模态窗口内选定的用户。

感谢您的帮助

最佳答案

将"is"按钮上的单击绑定(bind)设置为实际执行删除的函数,并将删除按钮上的单击绑定(bind)设置为显示模式的函数。您可能希望该函数将当前项目存储在可观察对象中(itemToDelete 或类似的东西),以便实际的删除函数知道要删除什么。

关于javascript - Knockout js - 确认后从列表中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21581781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com