当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Web.getFolderByServerRelativeUrl方法代码示例

本文整理汇总了TypeScript中sp-pnp-js.Web.getFolderByServerRelativeUrl方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Web.getFolderByServerRelativeUrl方法的具体用法?TypeScript Web.getFolderByServerRelativeUrl怎么用?TypeScript Web.getFolderByServerRelativeUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sp-pnp-js.Web的用法示例。


在下文中一共展示了Web.getFolderByServerRelativeUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getDiscussionById

    /**
     * Get a disucssion feed by id
     * @param id the id of the associated page
     */
    public async getDiscussionById(associatedPageId: number): Promise<IDiscussion> {

        let web = new Web(_spPageContextInfo.webAbsoluteUrl);

        try {

            const discussion = await web.getList(this.discussionListServerRelativeUrl).items
                .filter(`AssociatedPageId eq ${ associatedPageId }`)
                .select("Id", "Folder", "AssociatedPageId")
                .expand("Folder")
                .top(1)
                .get();
            if (discussion.length > 0) {

                // Get replies from this discussion (i.e. folder)
                const query: CamlQuery = {
                    FolderServerRelativeUrl: `${this.discussionListServerRelativeUrl}/${discussion[0].Folder.Name}`,
                    ViewXml: `<View>
                                    <ViewFields>
                                        <FieldRef Name="Id"></FieldRef>
                                        <FieldRef Name="ParentItemID"></FieldRef>
                                        <FieldRef Name="Created"></FieldRef>
                                        <FieldRef Name="Modified"></FieldRef>
                                        <FieldRef Name="Body"></FieldRef>
                                        <FieldRef Name="ParenListId"></FieldRef>
                                        <FieldRef Name="LikedBy"></FieldRef>
                                        <FieldRef Name="LikesCount"></FieldRef>
                                    </ViewFields>
                                    <Query/>
                                </View>`,
                };

                const replies = await web.getList(this.discussionListServerRelativeUrl).getItemsByCAMLQuery(query);

                // Batch are not supported on Sharepoint 2013
                // https://github.com/SharePoint/PnP-JS-Core/issues/492
                const batch = pnp.sp.createBatch();
                const isSPO = _spPageContextInfo["isSPO"];

                // tslint:disable-next-line:array-type
                const discussionReplies: Promise<IDiscussionReply>[] = replies.map(async (reply) => {

                    web = new Web(_spPageContextInfo.webAbsoluteUrl);
                    let item;
                    // tslint:disable-next-line:prefer-conditional-expression
                    if (isSPO) {
                        item = await web.getList(this.discussionListServerRelativeUrl).items.getById(reply.Id).select("Author/Name", "ParentList/Id").expand("Author/Name", "ParentList/Id").inBatch(batch).get();
                    } else {
                        item = await web.getList(this.discussionListServerRelativeUrl).items.getById(reply.Id).select("Author/Name", "ParentList/Id").expand("Author/Name", "ParentList/Id").get();
                    }

                    const authorProperties = await this.getUserProperties(item.Author.Name);
                    const PictureUrl = authorProperties["PictureUrl"] ? authorProperties["PictureUrl"] : "/_layouts/15/images/person.gif?rev=23";

                    // tslint:disable-next-line:no-object-literal-type-assertion
                    return {
                        Author: {
                            DisplayName: authorProperties["DisplayName"],
                            Id: item.Author.Id,
                            PictureUrl,
                        },
                        Body: reply.Body,
                        Children: [],
                        Edited: reply.Modified,
                        Id: reply.Id,
                        LikedBy: reply.LikedByStringId ? reply.LikedByStringId.results : [],
                        LikesCount: reply.LikesCount ? reply.LikesCount : 0,
                        ParentItemID: reply.ParentItemID,
                        ParentListId: item.ParentList.Id,
                        Posted: reply.Created,
                        UserPermissions: await this.getCurrentUserPermissionsOnItem(reply.Id, item.Author.Name),
                    } as IDiscussionReply;
                });

                if (isSPO) {
                    await batch.execute();
                }

                // Get rating experience settings
                const folderSettings = await web.getFolderByServerRelativeUrl(this.discussionListServerRelativeUrl).properties.select("Ratings_VotingExperience").get();

                const ratingExperience: string = folderSettings.Ratings_x005f_VotingExperience;
                let areLikesEnabled;
                if (ratingExperience) {
                    areLikesEnabled = ratingExperience.localeCompare("Likes") === 0 ? true : false;
                }

                // tslint:disable-next-line:no-object-literal-type-assertion
                return {
                    AreLikesEnabled: areLikesEnabled,
                    AssociatedPageId: discussion[0].AssociatedPageId,
                    Id: discussion[0].Id,
                    Replies: await Promise.all(discussionReplies),
                    Title: discussion[0].Title,
                } as IDiscussion;

//.........这里部分代码省略.........
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:101,代码来源:SocialModule.ts


注:本文中的sp-pnp-js.Web.getFolderByServerRelativeUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。