【发布时间】:2017-03-16 01:13:38
【问题描述】:
我有以下(TypeScript/Angular2/SPFx 项目的一部分):
// Populate the regulatory documents dropdown
this.regulatoryDocumentsService.fetchRegulatoryDocumentsData().subscribe(
data => { this.regulatoryDocumentsData = data },
err => { window.console && console.log(err) }
);
地点:
public fetchRegulatoryDocumentsData(): Observable<RegulatoryDocument[]> {
var choicesArray: Array<RegulatoryDocument> = new Array<RegulatoryDocument>();
// Local environment
if (Environment.type === EnvironmentType.Local)
{
// Send dummy data to the form - this works
window.console && console.log("fetchRegulatoryDocumentsData(): Local workbench in use");
choicesArray.push(new RegulatoryDocument(1,"Document 1"));
choicesArray.push(new RegulatoryDocument(2, "Document 2"));
choicesArray.push(new RegulatoryDocument(3, "Document 3"));
return Observable.of<RegulatoryDocument[]>(choicesArray);
}
else if (Environment.type == EnvironmentType.SharePoint ||
Environment.type == EnvironmentType.ClassicSharePoint)
{
// fetchRegulatoryDoocumentsData() is undefined. when I try to subscribe to it.
pnp.sp.web.lists.getByTitle('Regulatory Documents').items.get().then((choices: any[]) => {
window.console && console.log("choices ...");
window.console && console.log(choices);
if (choices) {
//choices.forEach((choice) => {
// choices.push(new Rating(choice));
//});
//Array.from(choices).forEach(function (child) {
// window.console && console.log(child)
//});
[].slice.call(choices).forEach(choice => {
choicesArray.push(new RegulatoryDocument(choice.ID, choice.Title));
});
}
return Observable.of<RegulatoryDocument[]>(choicesArray);
});
}
}
但是,如果Environment.type != EnvironmentType.Local 出现问题。当我尝试订阅时,它说不能订阅未定义。我怀疑这是因为嵌套的 PNP 承诺。任何想法都非常感谢。
【问题讨论】:
标签: angular typescript