【问题标题】:using SPservices to check current user exists in list使用 SPservices 检查当前用户是否存在于列表中
【发布时间】:2016-11-04 11:25:36
【问题描述】:

我使用 jquery/spservices 创建了一个脚本,用于检查当前登录的用户 ID 是否出现在自定义列表中名为 userid 的列中。如果成功,它会返回一个提醒说找到当前用户。

但是,如果未找到用户 ID,我希望另一个提醒说“您尚未注册”之类的内容。它在查找用户 ID 的位置时确实有效,但似乎无法判断它不存在。

任何帮助将不胜感激:)

代码如下:

var userName = $().SPServices.SPGetCurrentUser({
fieldName: "UserName"});var query = '<Query>' +
'<Where>' +
'<Eq>' +
'<FieldRef Name="userid" />' +
'<Value Type="User">' + userName + '</Value>' +
'</Eq>' +
'</Where>' +
'</Query>';$(document).ready(function() {
$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "test",
    CAMLViewFields: "<ViewFields><FieldRef Name='userid' /></ViewFields>",
    completefunc: function(xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
            if (userName == $(this).attr("ows_userid")) {
                alert("current user found");
            } else {
                alert("You need to register before accessing..");
            }
        });
    }
});});</script>

【问题讨论】:

    标签: jquery sharepoint-2013 spservices


    【解决方案1】:

    你可以试试下面的完整功能吗:

    completefunc: function(xData, Status) {
    
        var matchFound = false; //define flag
    
        //loop through all rows
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
            if (userName == $(this).attr("ows_userid")) {
                matchFound = true; //set the flag to true indicating matched record
            } 
        });
    
        if(matchFound)
            alert("current user found");
        else
            alert("You need to register before accessing..");
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-16
      • 2019-07-30
      • 1970-01-01
      • 2018-04-23
      相关资源
      最近更新 更多