質問

I've found various methods to return the default values for the field template override, including lookup, but I have been unable to find or successfully implement a method to do the same for fields in a Item Template that are not simply text (i.e. Lookup, People and Groups, etc...). In my code below, I would like to have the lookup field (ctx.CurrentItem.solSiteActSitesStatus) render as it normally would, as a modal dialog link to the item, in OTB list views. With this code, I get [object Object].

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function () {
function init() {
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        Templates: {
            Item: function (ctx) {
                var varItemTitle = ctx.CurrentItem.Title;
                var varSiteLocStatus = ctx.CurrentItem.solSiteActSitesStatus;
                varSiteLocHtml = "<tr class=\"ms-itmHoverEnabled ms-itmhover\" role=\"row\">" +
                    "<td height=\"100%\" class=\"ms-cellstyle ms-vb-title\" colspan=\"99\">" +
                    "<div title=\"Item Details\" style=\"cursor:pointer;\" class=\"link-set\"><div>" + varItemTitle +
                    "</div><div>Status: " + varSiteLocStatus +
                    "</div></div></td></tr>";
                return varSiteLocHtml;
            }
        }
    });
}
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~site/SiteAssets/js/kdeReqSiteLocItemCSR-TESTING2.js"), init);
init();

});

役に立ちましたか?

解決

You could try (ensure that the column name is in quotes)

var varSiteLocStatus = ctx.RenderFieldByName(ctx, "solSiteActSitesStatus");

Check out this article and scroll down to the section on "calling nested templates." The ctx object provides access to the all the different rendering methods used by SharePoint, so for any particular level you should be able to get the default HTML generated by SharePoint.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top