应用程序部分问题,_spPageContextInfo

时间:2015-01-15 13:37:13

标签: sharepoint-2013 csom

我正在尝试创建一个包含应用程序部分的SharePoint托管应用程序,此应用程序部分应显示用户正在关注的内容。我在应用程序中使用了工作代码作为示例,但我没有让它在App部件内部工作。

我在应用程序部分得到了这个:“Uncaught ReferenceError:_spPageContextInfo未定义”。

如果有人有一个真实的例子如何在应用程序部分中进行此工作,并使用social.following,请帮助!

这是App.js中的代码:

    var headline = new Array("People", "Documents", "Sites");
    var ActorImg = new Array("/_layouts/15/images/person.gif", "/_layouts/15/images/lg_ICGEN.gif",         "/_layouts/15/images/siteicon_16x16.png");

function doJSON(RESTuri, success, fail) {
    var restUrl = _spPageContextInfo.webAbsoluteUrl + RESTuri;
    var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
    executor.executeAsync(
    {
        url: restUrl,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: success,
        error: fail
    }
    );
}


function renderSuccess(data) {
    var jsonObject = JSON.parse(data.body);
    var n = document.getElementById('jsonout');
    n.innerHTML = data.body;
    var results = jsonObject.d.Followed.results;
    var str = '';
    var old = -1;
    var img = null;

    for (j = 0; j < 5; j++) {
        str += "<div class=\"container container" + j + "\">";
        for (i = 0; i < results.length; i++) {
            if (j != results[i].ActorType) continue;
            if (old != results[i].ActorType) str += "<h1 class=\"headline" + results[i].ActorType + "\">" + headline[results[i].ActorType] + "</h1>";

            img = results[i].ImageUri;
            if (img == null) img = ActorImg[results[i].ActorType];

            switch (results[i].ActorType) {
                case 0:
                    // Use case: depending on ActorType if you want to use indiviual markup for every item-type
                    str += "<a title=\"" + results[i].Name + "\" class=\"link" + results[i].ActorType + "\" style=\"background-image:url(" + img + ")\" href=\"" + results[i].Uri + "\">" + results[i].Name + "</a>";
                    break;
                default:
                    str += "<a title=\"" + results[i].Name + "\" class=\"link" + results[i].ActorType + "\" style=\"background-image:url(" + img + ")\" href=\"" + results[i].Uri + "\">" + results[i].Name + "</a>";
                    break;
            }

            old = results[i].ActorType;
        }
        str += "</div>";
    }

    n = document.getElementById('htmlout');
    n.innerHTML = str + "<h1></h1>";
}

function renderFail(data, errorCode, errorMessage) {
    n = document.getElementById('htmlout');
    n.innerHTML = errorMessage;
}

$(document).ready(function () {


    doJSON("/_api/social.following/my/followed%28types=15%29", renderSuccess, renderFail);
});

这是在应用页面(default.aspx)和应用程序部分页面(AppPart.aspx)中使用的div:

<div class="classic">
        <pre id="jsonout" style="display: none;"></pre>
        <div id="htmlout"></div>
</div> 

1 个答案:

答案 0 :(得分:0)

对不起伙计们。我通过添加对sp.requestexecutor.js文件的引用解析了它,并从查询字符串中解析了host-和app-url