JSLink在列上执行函数
问题描述:
是否可以在file.Js的列上执行函数?例如:Suppliers
是我的专栏名称。JSLink在列上执行函数
我想执行一个功能
var lookupSample = lookupSample || {};
lookupSample.CustomizeFieldRendering = function() {
// Intialize the variables for overrides objects
var overrideCtx = {
Templates: {
Fields: {
'Suppliers': {
'NewForm': lookupSample.singleLookupValue
},
}
}
};
overrideCtx.Templates.OnPostRender = PostRenderJs;
// Register the override of the field
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
}
lookupSample.singleLookupValue = function(ctx) {
var output = [];
var field = ctx.CurrentFieldSchema.Choices;
output.push('<div class="ui-widget"> <select id="combobox">');
// Check if field contains data
if (field.length > 0) {
for (i = 0; i < field.length; i++) {
output.push('<option id="');
output.push(field[i].LookupId);
output.push('">');
output.push(field[i].LookupValue);
output.push('</option>');
}
output.push('</select></div>');
}
// Push the value to the array
return output.join('');
}
function PostRenderJs (ctx){
alert('Hello World');
}
lookupSample.CustomizeFieldRendering();
此代码做我想做什么,但它开3(因为我有3列在我的名单,如果我有4列,即弹出4次,等)警报与相同的消息。
而且我只想弹出此消息1次(根据我的列Suppliers
)。
喜欢的东西
function PostRenderJs (ctx){
if(ctx.columnname=="Suppliers"){
alert('Hello World');
}
};
因此,这将弹出的Hello World只有1次。如果你想执行一段特定的域代码而已,你可以直接写代码为特定领域
:
答
请参考下面的代码片段。
var options = {
Templates: {
Fields: {
'Field1_Internal_Name': {
View: /* function or string */,
EditForm: /* function or string */,
DisplayForm: /* function or string */,
NewForm: /* function or string */
},
}
},
};
在参照上面的代码中,
与字段的内部名称取代 “Field1_Internal_Name”
指定无论您是书面方式您的视图代码,EditForm,DisplayForm ,NewForm
编写代码。
参考:https://www.codeproject.com/Articles/620110/SharePoint-Client-Side-Rendering-List-Views
我编辑我的职务。 我只需要知道如何执行一个函数,当columnname =列 –