CAML 查询 - 删除 1 个项目 [英] CAML Query - Delete 1 Item

查看:54
本文介绍了CAML 查询 - 删除 1 个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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>",

我的问题是删除多行而不仅仅是一行

My issue is that it is delete multiple rows and not just one

感谢所有帮助

推荐答案

您的问题不清楚.你想达到什么目的?GetListItems 是获取列表项,不是删除.因此,如果您想使用 WHERE 子句删除项目,您必须先调用 GetListItems,然后调用 UpdateListItems 以提供您要删除的项目的 ID.传递给 DeleteItems 的项目"是否只会从篮子列表中返回一条记录?

Your question is not clear. What are you trying to achieve? GetListItems is to get the list items, not to delete. So if you want to delete items with a WHERE clause you have to call GetListItems first, and then call UpdateListItems in providing the ID of the items you want to delete. Is your "itemit" passed to DeleteItems will return only ONE record from the Basket list?

你的代码应该是这样的:

Your code should look like that :

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/

FYI I've created a library that is easier to use: http://aymkdn.github.io/SharepointPlus/

对于您的代码,它看起来像:

For your code it will look like :

function DeleteItem(itemid) {
  // here I suppose that `itemid` will return only one record
  $SP().list("Basket").remove({
    where:"Item = '"+itemid+"'", 
    success:function() { alert("Done!") }
  })
}

这篇关于CAML 查询 - 删除 1 个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆