1
我正在將AngularJS應用程序轉換爲從SharePoint獲取一些數據的Angular 4。它使用JSOM,並使用executeQueryAsync()方法。轉換AngularJS承諾JSOM的AngularX observable
我想從服務器獲取executeQueryAsync()的數據,並將其存儲在服務中的observable中。我必須從舊版本(這不是我)轉換的代碼如下。現在我在將它轉換爲我的服務時遇到了語法問題。我絕對沒有計劃如何將此轉化爲角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;
}