简体   繁体   English

具有多行文本的Kendo MVC UI TreeList

[英]Kendo MVC UI TreeList with multi-line text

I added text-area as EditorTemplate (StringTextArea.cshtml) to TreeList. 我将文本区域添加为EditorTemplate(StringTextArea.cshtml)到TreeList。

@model string

@(Html.TextAreaFor(m => m, new { @class = "k-input k-textbox" }))

Model class 模型类

public class LevelViewModel
{
    public int Id { get; set; }
    public string LvlName { get; set; }
    [UIHint("StringTextArea")]
    public string LvlType { get; set; }
}

TreeList adds text-area in edit mode and I replace '\\n' in LvlType to ' <br /> ' before saving it to SQL Server 2008 TreeList在编辑模式下添加文本区域,我将LvlType中的'\\ n'替换为' <br /> ',然后将其保存到SQL Server 2008

LvlType = lvl.LvlType.Replace("\n", "<br />")

But it displays the string as it is, in the TreeList. 但它在TreeList中显示字符串。

在此输入图像描述

Is there any way to make the TreeList to display the string with line breaks? 有没有办法让TreeList显示带换行符的字符串?

Thanks 谢谢

My first idea to replace the encoded <br /> was really making it more complicated than it has to be :(. 我的第一个想法是更换编码的<br />真的让它变得比它更复杂:(。

Best solution is to make a template: template: "#=LvlType#" 最佳解决方案是制作模板:模板:“#= LvlType#”

When using # = # it will not encode, when using # : # it will encode! 当使用#=#时,它将不会编码,当使用#:#它将编码! My test: Telerik dojo 我的测试: Telerik道场

<html>
<head>
<base href="https://demos.telerik.com/kendo-ui/treelist/local-data-binding">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.material.mobile.min.css" />

<script src="https://kendo.cdn.telerik.com/2019.2.514/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.2.514/js/kendo.all.min.js"></script>

</head>
<body>
    <div id="example">
        <div id="treelist"></div>

        <script>
            $(document).ready(function () {
                var dataSource = new kendo.data.TreeListDataSource({
                    data: [
                      { id: 1, Name: "Daryl <br/>Sweeney", Position: "CEO", Phone: "(555) 924-9726", parentId: null },
                    ],

                    schema: {
                        model: {
                            id: "id",
                            expanded: true
                        }
                    }
                });

                $("#treelist").kendoTreeList({
                    dataSource: dataSource,
                    height: 540,
                    columns: [
                        { field: "Position" },
                        { field: "Name", template: "#=Name#" },
                        { field: "Phone" }
                    ]
                });
            });
        </script>
    </div>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM