选择复选框并将其作为参数发送给操作
我正在尝试对项目列表实施大规模删除操作,其中每个项目都有一个复选框,并且有一个按钮用于删除所有选定的项目。顺便说一句,所有这些都在 symfony 中。
我最大的问题是:带有复选框的列表来自 AJAX 调用,因此我无法在定义列表的模板中定义侦听器。我需要在接收 AJAX 响应的模板中执行此操作。
我给你一些我的代码:
- 返回列表的模板包含:
`
foreach($items as $item){
echo '<input id="'.$item->getItemID().'" type="checkbox" onClick="[I CAN'T REFERENCE HERE A FUNCTION IN THE OTHER TEMPLATE]">';
echo 'etc ...';
}`
- 并且接收列表的模板是
`
<div id="itemList">
[the AJAX list goes here]
</div>
<input type="button" value="delete all items">`
所以我的问题是:我怎样才能做到这一点,当按下按钮时,调用 symfony 操作以一组选定的复选框(或等效信息)作为参数。
非常感谢您抽出时间!
i'm trying to implement a massive delete action to a list of items, where every item has a checkbox, and there is a button to delete all the selected items. All that in symfony btw.
My biggest problem is: that list with the checkboxes comes from an AJAX call, so i can't define the listeners in the template where the list is defined. I need to do it in the template that recieves the AJAX response.
i give you some of my code:
- the template returning the list contains:
`
foreach($items as $item){
echo '<input id="'.$item->getItemID().'" type="checkbox" onClick="[I CAN'T REFERENCE HERE A FUNCTION IN THE OTHER TEMPLATE]">';
echo 'etc ...';
}`
- and the template recieving the list is
`
<div id="itemList">
[the AJAX list goes here]
</div>
<input type="button" value="delete all items">`
So my question is: How can i do it to implement that, when the button is pressed, call to for a symfony action with an array of selected checkboxes (or equivalent information) as parameter.
Thank you very much for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要做的第一件事是获取复选框数组并将它们传递给 symfony。如果您有以下
html
:和以下
jquery
:请参见此处:http://jsfiddle.net/HbkvF/
然后你执行
executeDeleteBatch()
类似的操作(未测试):$count
返回项目数已删除。The first thing to do is get the array of checkboxes and pass them to the symfony. If you have the following
html
:with the following
jquery
:See here: http://jsfiddle.net/HbkvF/
Then you do a
executeDeleteBatch()
something like (not tested):$count
returns the number of items deleted.