CAMLQuery: "<Query><Where><And><Eq><FieldRef Name='Item' />
<Value Type='Lookup'>" + itemid + "</Value></Eq><Eq>
<FieldRef Name='Author' /><Value Type='Integer'>
<UserID /></Value></Eq></And></Where><OrderBy>
<FieldRef Name='ID' Ascending='FALSE' /></OrderBy>
<RowLimit>1</RowLimit></Query>",
我的问题是删除多行而不只是一行
所有帮助都是
答案 0 :(得分:0)
最后我不得不做一个非常可怕的解决方法:
function DeleteItem(itemid) {
$().SPServices({
operation: "GetListItems",
async: false,
webURL: "MYURL",
listName: "Basket",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Item' /> <FieldRef Name='Item:Title' /></ViewFields>",
CAMLQuery: "<Query><Where><And><Eq><FieldRef Name='Item' /><Value Type='Lookup'>" + itemid + "</Value></Eq><Eq><FieldRef Name='Author' /><Value Type='Integer'><UserID /></Value></Eq></And></Where><OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
alert($(this).attr("ows_ID"));
$().SPServices.SPUpdateMultipleListItems({
listName: "Basket",
webURL: "MYURL",
CAMLRowLimit: 1,
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + $(this).attr("ows_ID") + "</Value></Eq></Where></Query>",
batchCmd: "Delete",
completefunc: function(xData, Status) {
CountItems();
ViewBasket();
CreateSuccess('Item deleted');
if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } // Stop the form acting like it normally would (refreshing the page)
}});
return false;
});
}
});
return true;
}
基本上我必须进行所有项目查找,查看每个项目,在ID上删除它并在第一次迭代后中断循环。可怕的解决方法,但无法想到另一种方法。
答案 1 :(得分:0)
你的问题不明确。你想要实现什么目标? GetListItems
是获取列表项,而不是删除。因此,如果要删除带有WHERE子句的项目,则必须先调用GetListItems
,然后在提供要删除的项目的ID时调用UpdateListItems
。是你的'#34; itemit&#34;传递给DeleteItems
只会从篮子列表中返回一条记录吗?
您的代码应如下所示:
function DeleteItem(itemid) {
$().SPServices({
operation: "GetListItems",
async: true, /* don't use FALSE ! */
webURL: "MYURL",
listName: "Basket",
CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='Item' /><FieldRef Name='Item:Title' /></ViewFields>",
CAMLQuery: "<Query><Where><And><Eq><FieldRef Name='Item' /><Value Type='Lookup'>" + itemid + "</Value></Eq><Eq><FieldRef Name='Author' /><Value Type='Integer'><UserID /></Value></Eq></And></Where><OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy></Query>",
completefunc: function (xData, Status) {
// use `.eq(0)` to look at the first one only
$(xData.responseXML).SPFilterNode("z:row").eq(0).each(function() {
alert($(this).attr("ows_ID"));
var ID = $(this).attr("ows_ID");
// now delete it with `UpdateListItems`
$().SPServices({
operation: "UpdateListItems",
webURL: "MYURL",
listName: "Basket",
updates: '<Batch OnError="Continue" ListVersion="1" ViewName=""><Method ID="1" Cmd="Delete"><Field Name='ID'>"+ID+"</Field></Method></Batch>',
completefunc: function (xData, Status) {
alert("OK")
}
});
})
}
})
}
仅供参考我已经创建了一个更易于使用的库:http://aymkdn.github.io/SharepointPlus/
对于您的代码,它将如下所示:
function DeleteItem(itemid) {
// here I suppose that `itemid` will return only one record
$SP().list("Basket").remove({
where:"Item = '"+itemid+"'",
success:function() { alert("Done!") }
})
}