【问题标题】:Sharepoint 2013, JS link people picker field not working saving for multiple usersSharepoint 2013,JS 链接人员选择器字段无法为多个用户保存
【发布时间】:2019-12-09 16:13:50
【问题描述】:

我正在使用以下 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/112576Sharepoint 2013 - EditForm, people picker new value not saving

【问题讨论】:

    标签: jquery sharepoint-2013 jslink sharepoint-addin


    【解决方案1】:

    这是我的示例测试演示:

    <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>
    

    【讨论】:

      猜你喜欢
      • 2015-02-15
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多