0

我正在使用以下 CSR 代码将 peoplepicker 值设置为多人。我有多个用户要分配到我的 peoplepicker 字段。当我通过当前用户时,该代码有效,但不适用于其他值。

function renderAssignedTo(ctx) {
 //get current user properties
 //var currentUser = $().SPServices.SPGetCurrentUser({fieldNames: ["Title", "Name"]});   //get current user properties
 if(ctx.results!=undefined)
 {
     ctx.CurrentFieldValue = [];
     for(var i=0; i<ctx.results.length;i++)
     {
         var currentUserEntry = createUserEntity(ctx.results[i].Name,ctx.results[i].Title);
         ctx.CurrentFieldValue.push(currentUserEntry); 
     }
 }       
 return SPClientPeoplePickerCSRTemplate(ctx);
}

这里ctx有一组用户名和标题。需要为NewForm.aspx接受多个值的 peoplepicker 字段设置这些值。

我参考了这篇文章

1https ://sharepoint.stackexchange.com/questions/112506/sharepoint-2013-js-link-return-default-field-rendering/112576和Sharepoint 2013 - EditForm,人员选择器新值不保存

4

1 回答 1

0

这是我的示例测试演示:

<script type="text/javascript">
        (function () {
            SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
                Templates: {
                    Fields: {
                        "UserField": {
                            "NewForm": setDefaultUser
                        }
                    }
                }
            });
        })();

        function setDefaultUser(ctx) {
            ctx.CurrentFieldValue = [{
                Description: "",
                DisplayText: "Lee",
                EntityGroupName: "",
                EntityType: "",
                HierarchyIdentifier: null,
                IsResolved: true,
                Key: "contoso\\lee",
                MultipleMatches: [],
                ProviderDisplayName: "",
                ProviderName: ""
            },
            {
                Description: "",
                DisplayText: "Administrator",
                EntityGroupName: "",
                EntityType: "",
                HierarchyIdentifier: null,
                IsResolved: true,
                Key: "contoso\\administrator",
                MultipleMatches: [],
                ProviderDisplayName: "",
                ProviderName: ""
            }
            ];
            // Return the html for the user field
            return SPClientPeoplePickerCSRTemplate(ctx);
        }
    </script>

在此处输入图像描述

于 2019-08-02T05:31:45.610 回答