Как я могу показать источник HTML внутри всплывающей подсказки - PullRequest
0 голосов
/ 13 марта 2019

У меня есть следующий скрипт JSLINK: -

(function () {

    // Create object that have the context information about the field that we want to change it's output render 
    var bodyFiledContext = {};
    bodyFiledContext.Templates = {};
    bodyFiledContext.Templates.Fields = {
        // Apply the new rendering for Body field on list view
        "Body": { "View": bodyFiledTemplate }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext);

})();

// This function provides the rendering logic
function bodyFiledTemplate(ctx) {

    var bodyValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];


    bodyValue = bodyValue.replace(regex, "");

    var newBodyValue = bodyValue;

    if (bodyValue && bodyValue.length >= 100)
    {
        newBodyValue = bodyValue.substring(0, 100) + " ...";
    }

    return "<span title='" + bodyValue + "'>" + newBodyValue + "</span>";

}

Который в основном берет первые 100 символов, а затем показывает полный текст внутри всплывающей подсказки. но проблема, с которой я сталкиваюсь, состоит в том, что ctx.CurrentItem[ctx.CurrentFieldSchema.Name] является HTML-кодом, поэтому внутри подсказки я получу фактические HTML-теги, в то время как я хочу показать фактические данные, а не исходный HTML. так я могу это сделать?

EDIT

Вот пример кода HTML для одного поля (я заменил реальный текст точками ..): -

<div class="ExternalClass365A46B23B5F4AE38B2909AB3EF63011"><ul><li><p>​Ticket was raised March 1st 7&#58;28</p></li><li><p>User indicated ....</p></li><li><p>No action ....s</p></li><li><p>........</p></li><li><p>............</p></li><li><p>.....</p></li></ul><p><br></p></div>

и я обновил свой скрипт следующим образом: -

bodyValue.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { return '&#'+i.charCodeAt(0)+';'; });,

следующим образом: -

(function () { 

    // Create object that have the context information about the field that we want to change it's output render  
    var bodyFiledContext = {}; 
    bodyFiledContext.Templates = {}; 
    bodyFiledContext.Templates.Fields = { 
        // Apply the new rendering for Body field on list view 
        "UserFeedbackAnalysis": { "View": bodyFiledTemplate } 
    }; 

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 

})(); 

// This function provides the rendering logic 
function bodyFiledTemplate(ctx) { 

    var bodyValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 



    var newBodyValue = ""; 

    if (bodyValue && bodyValue.length >= 100) 
    { 
        newBodyValue = bodyValue.substring(0, 100) + " ..."; 
    } 
    var fullval = bodyValue.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
   return '&#'+i.charCodeAt(0)+';';
});

    return "<span title='" + fullval + "'>" + newBodyValue + "</span>"; 

} 

теперь усечение произойдет ... но во всплывающей подсказке я все еще получаю реальные HTML-теги, как показано ниже: - enter image description here

...