我正在将 AngularJS 应用程序转换为从 SharePoint 获取一些数据的 Angular 4。它使用 JSOM 和 executeQueryAsync() 方法。
我想使用 executeQueryAsync() 从服务器获取数据并将其存储在我的服务中的可观察对象中。我必须从旧版本(不是我的)转换的代码如下。现在,我在将其转换为我的服务时遇到了语法问题。我完全没有计划如何将其转换为 Angular 4。
getAllStatusReps($scope) {
const deferred = $q.defer();
const ctx = SP.ClientContext.get_current();
const web = ctx.get_web();
const statusList = web.get_lists().getByTitle(this.statusListName);
const twitterList = web.get_lists().getByTitle(this.twitterListName);
const statReps = statusList.getItems(this.getQueryForAllStatusReps());
const twitReps = twitterList.getItems(this.getQueryForAllStatusReps());
const queryText = `
<View>
<RowLimit>1</RowLimit>
<ViewFields>{0}</ViewFields>
<Query>
<Where><IsNotNull><FieldRef Name=\'EPMStatusDate\' /></IsNotNull></Where>
<OrderBy><FieldRef Name=\'ID\' Ascending= \'False\' /></OrderBy>
</Query>
</View>`;
const statCamlQuery = new SP.CamlQuery();
statCamlQuery.set_viewXml(String.format(queryText, this.getViewFields(true, false)));
const lastStatRep = statusList.getItems(statCamlQuery);
const twitCamlQuery = new SP.CamlQuery();
twitCamlQuery.set_viewXml(String.format(queryText, this.getViewFields(false, false)));
const lastTwitRep = twitterList.getItems(twitCamlQuery);
ctx.load(statReps);
ctx.load(twitReps);
ctx.load(lastStatRep);
ctx.load(lastTwitRep);
ctx.executeQueryAsync(
function () {
deferred.resolve({
statReps: statReps,
twitReps: twitReps,
lastStatRep: lastStatRep,
lastTwitRep: lastTwitRep
});
},
function (sender, args) {
deferred.reject('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
);
return deferred.promise;
}