java程序:
/**
* 删除
*/
@RequestMapping(value = "/deleteBest", method = RequestMethod.POST ,produces = "application/json; charset=utf-8")
public @ResponseBody
String deleteBest(Long id,Long bestid) {
String error = "参数错误!";
if(id == null || bestid == null)
{
return "$.message(\"" + Message.Type.success + "\", \"" + error + "\");";
}
else
{
Product product = productService.find(id);
if(product != null)
{
Set<Product> bests = product.getBestGroup();
Iterator<Product> iter = bests.iterator();
while(iter.hasNext())
{
Product p = iter.next();
if(p.getId() == bestid)
{
iter.remove();
}
}
product.setBestGroup(bests);
productService.update(product);
String success = "删除成功!";
return "$.message(\"" + Message.Type.success + "\", \"" + success + "\");";
}
}
return "$.message(\"" + Message.Type.success + "\", \"" + error + "\");";
}
前台程序:
//删除一个最佳组合
function deleteBest(id,bestid)
{
$.ajax({
url:"deleteBest.jhtml",
type:"post",
data:{
id:id,
bestid:bestid
},
dataType:"script",
success:function(msg)
{
//执行脚本并删除节点
eval(msg);
$("#li"+bestid).remove();
var index = array.indexOf(id);
array.remove(index);
}
});
}