SharePoint 列表 CSR 默认呈现回退
SharePoint list CSR default rendering fallback
我在 Internet 上搜索时发现了几个很好的示例,但主要与渲染表单的默认渲染方法有关。
我的情况是,我在两个具有不同视图的 Web 部件中有一个包含相同列表的页面,其中一个我想为另一个应用 CSR,我只想使用默认呈现。有人提到您可以检查视图 ID 并调用 RenderFieldValueDefault(ctx),但这似乎不起作用,输出为 none。
以下是我的尝试:
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates', function () {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Fields: {
AnyFieldInternalName: {
View: function (ctx) {
if (ctx.listName !== 'some_unique_id') {
return RenderFieldValueDefault(ctx);
}
return 'haha';
},
},
},
},
OnPreRender: __customPreRender,
OnPostRender: __customPostRender,
});
});
有谁知道如何在无需自定义处理 "default fields" 的情况下实现此目的?
谢谢,
对于任何想知道的人,我能够使用 clienttemplates.debug.js
中的以下代码来完成
/**
* default render method taken from clienttemplates.debug.js
* @param {Object} root the global root, in this case this is bound to window.
* @param {Object} anCtx current context of the list
* @param {Object} aField current field
* @param {Object} anItem current item
* @param {Object} aListSchema current list schema
*/
var DefaultRenderFallBack = (function (root, anCtx, aField, anItem, aListSchema) {
var fieldRenderMap = {
Computed: new root.ComputedFieldRenderer(aField.Name),
Attachments: new root.AttachmentFieldRenderer(aField.Name),
User: new root.UserFieldRenderer(aField.Name),
UserMulti: new root.UserFieldRenderer(aField.Name),
URL: new root.UrlFieldRenderer(aField.Name),
Note: new root.NoteFieldRenderer(aField.Name),
Recurrence: new root.RecurrenceFieldRenderer(aField.Name),
CrossProjectLink: new root.ProjectLinkFieldRenderer(aField.Name),
AllDayEvent: new root.AllDayEventFieldRenderer(aField.Name),
Number: new root.NumberFieldRenderer(aField.Name),
BusinessData: new root.BusinessDataFieldRenderer(aField.Name),
Currency: new root.NumberFieldRenderer(aField.Name),
DateTime: new root.DateTimeFieldRenderer(aField.Name),
Text: new root.TextFieldRenderer(aField.Name),
Lookup: new root.LookupFieldRenderer(aField.Name),
LookupMulti: new root.LookupFieldRenderer(aField.Name),
WorkflowStatus: new root.RawFieldRenderer(aField.Name),
};
if (!(root.OffSwitch == null || root.OffSwitch.IsActive('39A8E192-9EFC-4922-9FD8-343D685E163C'))) {
fieldRenderMap.Location = new root.LocationFieldRenderer(aField.Name);
}
// eslint-disable-next-line eqeqeq
if (aField.XSLRender == '1') {
/* eslint-disable no-param-reassign */
aField.FieldRenderer = new root.RawFieldRenderer(aField.Name);
} else {
aField.FieldRenderer = fieldRenderMap[aField.FieldType];
if (aField.FieldRenderer == null) { aField.FieldRenderer = fieldRenderMap[aField.Type]; }
}
if (aField.FieldRenderer == null) { aField.FieldRenderer = new root.FieldRenderer(aField.Name); }
/* eslint-enable no-param-reassign */
return aField.FieldRenderer.RenderField(anCtx, aField, anItem, aListSchema);
}.bind(null, window));
所以我可以做类似的事情
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates', function () {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Fields: {
AnyFieldInternalName: {
View: function (ctx, field, item, schema) {
if (ctx.listName !== 'some_unique_id') {
return DefaultRenderFallBack (ctx, field, item, schema);
}
return 'haha';
},
},
},
},
OnPreRender: __customPreRender,
OnPostRender: __customPostRender,
});
});
您可以使用'ViewStyle'设置目标列表视图。
您可以将目标视图更改为其他样式,以便可以呈现。
我在 Internet 上搜索时发现了几个很好的示例,但主要与渲染表单的默认渲染方法有关。
我的情况是,我在两个具有不同视图的 Web 部件中有一个包含相同列表的页面,其中一个我想为另一个应用 CSR,我只想使用默认呈现。有人提到您可以检查视图 ID 并调用 RenderFieldValueDefault(ctx),但这似乎不起作用,输出为 none。
以下是我的尝试:
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates', function () {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Fields: {
AnyFieldInternalName: {
View: function (ctx) {
if (ctx.listName !== 'some_unique_id') {
return RenderFieldValueDefault(ctx);
}
return 'haha';
},
},
},
},
OnPreRender: __customPreRender,
OnPostRender: __customPostRender,
});
});
有谁知道如何在无需自定义处理 "default fields" 的情况下实现此目的?
谢谢,
对于任何想知道的人,我能够使用 clienttemplates.debug.js
中的以下代码来完成/**
* default render method taken from clienttemplates.debug.js
* @param {Object} root the global root, in this case this is bound to window.
* @param {Object} anCtx current context of the list
* @param {Object} aField current field
* @param {Object} anItem current item
* @param {Object} aListSchema current list schema
*/
var DefaultRenderFallBack = (function (root, anCtx, aField, anItem, aListSchema) {
var fieldRenderMap = {
Computed: new root.ComputedFieldRenderer(aField.Name),
Attachments: new root.AttachmentFieldRenderer(aField.Name),
User: new root.UserFieldRenderer(aField.Name),
UserMulti: new root.UserFieldRenderer(aField.Name),
URL: new root.UrlFieldRenderer(aField.Name),
Note: new root.NoteFieldRenderer(aField.Name),
Recurrence: new root.RecurrenceFieldRenderer(aField.Name),
CrossProjectLink: new root.ProjectLinkFieldRenderer(aField.Name),
AllDayEvent: new root.AllDayEventFieldRenderer(aField.Name),
Number: new root.NumberFieldRenderer(aField.Name),
BusinessData: new root.BusinessDataFieldRenderer(aField.Name),
Currency: new root.NumberFieldRenderer(aField.Name),
DateTime: new root.DateTimeFieldRenderer(aField.Name),
Text: new root.TextFieldRenderer(aField.Name),
Lookup: new root.LookupFieldRenderer(aField.Name),
LookupMulti: new root.LookupFieldRenderer(aField.Name),
WorkflowStatus: new root.RawFieldRenderer(aField.Name),
};
if (!(root.OffSwitch == null || root.OffSwitch.IsActive('39A8E192-9EFC-4922-9FD8-343D685E163C'))) {
fieldRenderMap.Location = new root.LocationFieldRenderer(aField.Name);
}
// eslint-disable-next-line eqeqeq
if (aField.XSLRender == '1') {
/* eslint-disable no-param-reassign */
aField.FieldRenderer = new root.RawFieldRenderer(aField.Name);
} else {
aField.FieldRenderer = fieldRenderMap[aField.FieldType];
if (aField.FieldRenderer == null) { aField.FieldRenderer = fieldRenderMap[aField.Type]; }
}
if (aField.FieldRenderer == null) { aField.FieldRenderer = new root.FieldRenderer(aField.Name); }
/* eslint-enable no-param-reassign */
return aField.FieldRenderer.RenderField(anCtx, aField, anItem, aListSchema);
}.bind(null, window));
所以我可以做类似的事情
SP.SOD.executeFunc('clienttemplates.js', 'SPClientTemplates', function () {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Fields: {
AnyFieldInternalName: {
View: function (ctx, field, item, schema) {
if (ctx.listName !== 'some_unique_id') {
return DefaultRenderFallBack (ctx, field, item, schema);
}
return 'haha';
},
},
},
},
OnPreRender: __customPreRender,
OnPostRender: __customPostRender,
});
});
您可以使用'ViewStyle'设置目标列表视图。
您可以将目标视图更改为其他样式,以便可以呈现。