0
我在sharepoint的顯示模板中有以下代碼,我有一個對象數組,並且需要獲得以下結果。如何迭代對象數組並打印出其中一個屬性
Name1
Name2
Name3
因此,我可以使用工具提示替換Sharepoint多人用戶字段的默認呈現。
不過,我不知道如何進行迭代,然後拼接:
截圖:
代碼:
// List View - Substring Long String Sample
// Muawiyah Shannak , @MuShannak
(function() {
// Create object that have the context information about the field that we want to change it's output render
var projectTeamContext = {};
projectTeamContext.Templates = {};
projectTeamContext.Templates.Fields = {
// Apply the new rendering for Body field on list view
"Project_x0020_Team": { "View": ProjectTeamTemplate }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(projectTeamContext);
})();
// This function provides the rendering logic
function ProjectTeamTemplate(ctx) {
var projectTeamValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
//newBodyvalue should have the list of all display names and it will be rendered as a tooltip automaticlaly
return "<span title='" + projectTeamValue + "'>" + newBodyValue + "</span>";
}
它自動由Sharepoint填充。如果你看到截圖,你會看到它的一些對象的數組,我只對Names屬性感興趣。 – 2014-10-07 11:31:18