qq_36203048
讲完这题就下课
2017-09-08 03:37

哪位大神帮我看看以下代码的问题 javascript读取不到sharepoint的列表

  • sharepoint
  • javascript
    var context = SP.ClientContext.get_current();
    var user = context.get_web().get_currentUser();
    var collListItem = "";
    var listItemEnumerator = "";
    var listItemInfo = "";
    var url = "/sites/Develop/ChildOne";

    $(document).ready(function () {

        retrieveListItems(url);

    });

    function retrieveListItems(siteUrl) {
        var clientContext = new SP.ClientContext(siteUrl);
        var oWebSite = clientContext.get_web();
        var oList = oWebSite.get_lists().getByTitle("MyList");
        var camlQuery = new SP.CamlQuery();

        collListItem = oList.getItems(camlQuery);

        clientContext.load(collListItem);

        clientContext.executeQueryAsync(onQuerySucceeded,onQueryFailed);

    }

    function onQuerySucceeded(sender, args) {

        listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            listItemInfo += "\nID: " + oListItem.get_id() +
                "<br/>"+"姓名: " + oListItem.get_item("Name") +
                "<br/>"+"身高: " + oListItem.get_item("Height") +
                "<br/>"+"年龄:" + oListItem.get_item("Age")+"<br/>";
        }

        alert(listItemInfo);
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
            '\n' + args.get_stackTrace());
    }

图片说明
错误提示说,属性或字段尚未初始化。 但不知道是哪没初始化。onQuerySucceeded方法和onQueryFailed方法都没有执行

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答