Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 在Asp.NETMVC中混合静态html和主干数据的最佳方法?_Backbone.js - Fatal编程技术网

Backbone.js 在Asp.NETMVC中混合静态html和主干数据的最佳方法?

Backbone.js 在Asp.NETMVC中混合静态html和主干数据的最佳方法?,backbone.js,Backbone.js,目前,我被迫使用字符转义来混合静态html和模型数据,但必须有更好的方法 我目前正在使用.aspx视图,这就是我的一些视图的丑陋程度 $('ul#spaceImage', this.el).append("<li id=\"" + item.get("HoverId") + "\" class=\"hover\" style=\"left:" + x + "px;top:" + y + "px\"><span class=\"newlyAdded\"></span&

目前,我被迫使用字符转义来混合静态html和模型数据,但必须有更好的方法

我目前正在使用.aspx视图,这就是我的一些视图的丑陋程度

$('ul#spaceImage', this.el).append("<li id=\"" + item.get("HoverId") + "\" class=\"hover\" style=\"left:" + x + "px;top:" + y + "px\"><span class=\"newlyAdded\"></span>" + item.get("MaterialGroupName") + "<a></a></li>");
$('ul#spaceImage',this.el.).append(
  • ”+item.get(“MaterialGroupName”)+“
  • ”;

    有没有一种方法可以在不转义字符的情况下显示此内容?

    我猜您在使用下划线模板时遇到了问题,因为它们共享asp.net语法?如果是这样,您可以使用模板代码并将其移动到asp标记中的脚本块

    标记:

    <script type="text/html" id="list-item-template">
      <li id="{{HoverId}}" class="{{hover}}" style="left:<%=x%>px;top:<%=y%>px">
        <span class="newlyAdded"></span>
        <a><{{MaterialGroupName}}></a>
      </li>
    </script>
    
    render: function() {
      var template = Handlebars.compile($("#list-item-template").html());
      $(this.el).html(template({this.model.toJSON()}));
      return this;
    }