Javascript 为什么在SharePoint2013中CSR自定义后web部件中不显示项目?

Javascript 为什么在SharePoint2013中CSR自定义后web部件中不显示项目?,javascript,sharepoint,sharepoint-2013,Javascript,Sharepoint,Sharepoint 2013,我尝试在SharePoint 2013中使用CSR Javascript文件自定义web部件,但在视图中进行了所有更改后,我使用文本[object object]的项目,而不是通常列出的项目。有什么问题吗 我的JS代码: (function () { /* * Initialize the variable that store the overrides objects. */ var overrideCtx = {}; overrideCtx.Templates = {}; // A

我尝试在SharePoint 2013中使用CSR Javascript文件自定义web部件,但在视图中进行了所有更改后,我使用文本[object object]的项目,而不是通常列出的项目。有什么问题吗

我的JS代码:

(function () {
/*
 * Initialize the variable that store the overrides objects.
 */
var overrideCtx = {};
overrideCtx.Templates = {};

 // Assign functions or plain html strings to the templateset objects:


//  This template is assigned to the CustomItem function.
overrideCtx.Templates.Group = CustomGroup;
overrideCtx.Templates.Item = CustomItem;

overrideCtx.BaseViewID = 1;
overrideCtx.ListTemplateType = 100;

//       Register the template overrides.

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

})();

 /*
 * This function builds the output for the item template.
 * Uses the Context object to access announcement data.
 */
function CustomItem(ctx) {
// Build a listitem entry for every announcement in the list.
var ret = '<div style="width: 150px; border: 1px solid #333; padding: 5px;"> <div> <div style="float: left; display: inline-block;">' + ctx.CurrentItem.Title + 
'</div> <div style="float: right; display: inline-block;">' + ctx.CurrentItem.TaskDueDate + '</div> </div> <div style="word-wrap: break-word;">' + ctx.CurrentItem.CategoryDescription + '</div> </div>';
return ret;
};

function CustomGroup(ctx, group, groupId, listItem, listSchema, level, expand) {
var html = '<div style="font-weight:bold; display: inline-block;">' + listItem[group] + ' ::'  + '<div><ul>'+listItem+ '</ul></div>' + '</div>';
return html;
};
(函数(){
/*
*初始化存储覆盖对象的变量。
*/
var overrideCX={};
overrideCtx.Templates={};
//将函数或普通html字符串分配给templateset对象:
//此模板已分配给CustomItem功能。
OverrideCEx.Templates.Group=CustomGroup;
OverrideCEx.Templates.Item=CustomItem;
OverrideCX.BaseViewID=1;
OverrideCEx.ListTemplateType=100;
//注册模板覆盖。
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(OverrideCX);
})();
/*
*此函数用于生成项模板的输出。
*使用上下文对象访问公告数据。
*/
功能自定义项(ctx){
//为列表中的每个公告构建listitem条目。
var ret=''+ctx.CurrentItem.Title+
''+ctx.CurrentItem.TaskDueDate+''+ctx.CurrentItem.CategoryDescription+'';
返回ret;
};
函数CustomGroup(ctx、group、groupId、listItem、listSchema、level、expand){
var html=''+listItem[group]+'::'+'
    '+listItem+'
'+''; 返回html; };
某些变量包含对象而不是字符串。这里有一种方法可以找出是哪一种

在设置和返回“ret”变量之间,向javascript添加一些输出跟踪。例如,在CustomItem中,您可以添加:

console.log("Title, Due Date, and Category are:);
console.log(ctx.CurrentItem.Title);
console.log(ctx.CurrentItem.TaskDueDate);
console.log(ctx.CurrentItem.CategoryDescription);
打开页面并使用浏览器显示控制台。()

在控制台中,您将看到处理的每个项目的四行输出。其中一个可能会说[Object],而不是您要查找的字符串值。 单击[Object]左侧的三角形图标以展开对象的属性

现在您可以看到对象结构,调整“ret”变量以获得字符串值。例如,它可能是ctx.CurrentItem.CategoryDescription.Title,而不仅仅是ctx.CurrentItem.CategoryDescription