我对ECB有疑问:在Sharepoint 2013中,如何使用JSLink创建编辑控件块(ECB)。
以下是我的自定义视图的图片:
SP2013中的标准视图:
这是我的JavaScript代码:
(function () {
var itemCtx = {};
itemCtx.Templates = {};
itemCtx.Templates.Item = ItemOverrideFun;
itemCtx.BaseViewID = 1;
itemCtx.ListTemplateType = 104;
itemCtx.OnPostRender = [];
itemCtx.OnPostRender.push(function () {
$(document).ready(function () {
// use this method to extend ECB on common lists...
function Custom_AddListMenuItems(m, ctx) {
// Adding a simple command to the ECB
CAMOpt(m, 'Go to', 'javascript:STSNavigate("http://www.abc.com");return false;');
// Adding a separator to the ECB
CAMSep(m);
}
// use this method to extend ECB on libraries...
function Custom_AddDocLibMenuItems(m, ctx) {}
});
});
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);
})();
function ItemOverrideFun(ctx) {
var id = ctx.CurrentItem["ID"];
var _announcementTitle = ctx.CurrentItem["Title"];
var _announcementDesc = ctx.CurrentItem["Content"];
var createBy = ctx.CurrentItem["Author"][0].title;
var modified = ctx.CurrentItem["Modified"];
var att = ctx.CurrentItem["Attachments"];
var attImg = "";
if (att == true) {
attImg = attImg + "<img src='/../../_layouts/15/images/attach.gif' /> ";
}
return "<tr><td></td><td vAlign='top' style='width:20px;padding-left:8px;'>" + attImg + "</td><td colspan='2' style='padding-left:40px;'><img style='cursor:pointer' onclick='Expand(" + id + ");' id='imgId" + id + "' src='" + L_Menu_BaseUrl + "/Images/minus.gif' /><span style='padding-left:5px'><a style='cursor:pointer;font-size:1em' href='" + L_Menu_BaseUrl + "/Lists/Bulletin%20Board/DispForm.aspx?ID=" + id + "'>" + _announcementTitle + "</a></span><div id='sh" + id + "' style='padding-left:15px;'>" + _announcementDesc + "</div></td><td>" + createBy + "</td><td>" + modified + "</td></tr>";
}
function Expand(id) {
var dsStatus = document.getElementById('sh' + id).style.display;
var url = L_Menu_BaseUrl;
if (dsStatus == 'none') {
jQuery("#imgId" + id).attr('src', url + '/Images/minus.gif');
$('#sh' + id).show();
}
else {
jQuery("#imgId" + id).attr('src', url + '/images/plus.gif');
$('#sh' + id).hide();
}
}
什么是ECB的struct HTML?我退回了缺少的ECB,那么我该如何解决这个问题呢?
答案 0 :(得分:2)
ECB未显示,因为结构HTML在ItemOverrideFun中返回不正确。
这是最终的Javascript代码: