Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Javascript检查Sharepoint列表中列的值是空还是空?_Javascript_Sharepoint - Fatal编程技术网

如何使用Javascript检查Sharepoint列表中列的值是空还是空?

如何使用Javascript检查Sharepoint列表中列的值是空还是空?,javascript,sharepoint,Javascript,Sharepoint,到目前为止,我可以根据传递的字符串甚至列名检索列表,但我不知道如何获取特定列的值。这是我到目前为止所拥有的 function GetFieldList() { var listname = document.getElementById("ListName").value; var ctx = SP.ClientContext.get_current(); this.web = ctx.get_web(); ctx.load(this.web); this.list = we

到目前为止,我可以根据传递的字符串甚至列名检索列表,但我不知道如何获取特定列的值。这是我到目前为止所拥有的

function GetFieldList()
{
  var listname = document.getElementById("ListName").value;
  var ctx = SP.ClientContext.get_current();
  this.web = ctx.get_web();
  ctx.load(this.web);
  this.list = web.get_lists().getByTitle(listname);
  ctx.load(this.list);
  this.fields = this.list.get_fields();
  ctx.load(this.fields); 
  ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

顺便说一句,我正在使用SharePoint 2010。

我认为您的代码未满。客户端上下文必须运行异步方法才能加载值 如果希望以正确的方式从SharePoint获取值,请阅读以下文档: 也可以使用其他库,如RESTAPI或SPSService。 无论如何,get_字段返回的是字段列表名称,而不是值

如您所说SP.ClientContext.get_current;是一个Javascript对象,因此首先需要检查想要知道是null还是空的属性是否存在

var ctx = SP.ClientContext.get_current();
isPropertyEmptyOrNull = ctx.hasOwnProperty('myProperty') && (prop.myProperty === null or prop.myProperty === '' or prop.myProperty === undefined)

您找到了有关hasOwnProperty的更多详细信息,请参阅下面的代码。这显示了如何从SharePoint列表中检索项目

function GetItems() {
    var context = new SP.ClientContext.get_current();
    var list = context.get_web().get_lists().getByTitle('ListName');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("");
    collItems = list.getItems(camlQuery);
    context.load(collItems);
    context.executeQueryAsync(GetItemsSuccess, GetItemsFail);
}

function GetItemsSuccess() {

    var listItemEnumerator = collItems.getEnumerator();

    if (collItems.get_count() > 0) {

        while (listItemEnumerator.moveNext()) {

            var oListItem = listItemEnumerator.get_current();

            /*
                retrieve specific fields (e.g. Title, FirstName...)
                Here 'Title' and 'FirstName' will be the internal name of the field you want to retrieve
            */
            var title = oListItem.get_item('Title');
            var firstName = oListItem.get_item('FirstName');

        }
    }
}

function GetItemsFail(sender, args) {
    // Error handler code 
}

是否检查SP.ClientContext.get_是否为当前;返回一个Javascript对象?我使用typeof方法检查ctx是什么数据类型,结果得到了一个对象。这有帮助吗?@myEdu您是否试图从sharepoint列表中的特定字段/列获取数据?同意!没有方法解析来自queryadded方法的结果来解析查询。