gpt4 book ai didi

javascript - 下划线模板(二合一)/Backbone

转载 作者:行者123 更新时间:2023-11-28 02:16:00 27 4
gpt4 key购买 nike

如何调用与 Underscore.js 模板中的模板不同的模板?

HTML 代码:

<*script id="editWrapView" type="text/template">
<div class="wrapperFields__leftUnderLine disp_intop"></div>
<div class="wrapperFields__titleItem disp_intop">
<span class="f_s_100"><%=title%></span>
</div>
<div class="wrapperFields__rightUnderLine disp_intop"></div>

<div class="wrapperFields__basicFields ">
<ul class="basicFields__ulList">
<li class="ulList__item">
<span class="question" title=""></span>
<label id="sortOrder" class="labelItem">SortOrder</label>
<input name="sortOrder" class="custom-input width_fields_input"/>
</li>
<li class="ulList__item">
<span class="question" title=""></span>
<label id="sortOrder" class="labelItem">TYPE</label>
<select class="width_fields_select">
<option value="1" <% if(type == 1){ %>selected<%}%> >Category</option>
<option value="2" <% if(type == 2){ %>selected<%}%>>Link</option>
<option value="3" <% if(type == 3){ %>selected<%}%>>Spacer</option>
<option value="4" <% if(type == 4){ %>selected<%}%>>Divider</option>
<option value="5" <% if(type == 5){ %>selected<%}%>>HTML</option>
</select>
</li>
</ul>
</div>
<div class="wrapperFields__changeFields disp_intop">
<%= _.template( $("#category_"+type).html(), this) %> <!-- QUESTION STRING -->
</div>
</*script>
<*script id="category_1" type="text/template">
<ul class="basicFields__ulList" id="1">
<li class="ulList__item">
<span class="question" title=""></span>
<label id="sortOrder" class="labelItem">ChooseCategory</label>
<select class="width_fields_select">
<option value="1" <% if (type == 1){ %>selected <% } %> >Category</option>
<option value="2">Link</option>
<option value="3">Spacer</option>
<option value="4">Divider</option>
<option value="5">HTML</option>
</select>
</li>
<li class="ulList__item">
<span class="question" title=""></span>
<label id="sortOrder" class="labelItem">LEVELS TO SHOW</label>
<input name="sortOrder" class="custom-input width_fields_input"/>
</li>
</ul>
</*script>

主干代码:

render : function(){
var tpl = _.template($("#editWrapView").html(), this.model.toJSON());
this.$el.html(tpl);
return this;
},

最佳答案

您可以渲染部分模板并将其添加到主模板中。

尝试这样的事情:

render: function(){
var tpl = _.template($("#editWrapView").html(), this.model.toJSON());
this.$el.html(tpl);

var partial = _.template($("#myPartial").html(), this.model.toJSON());
this.$el.find(".wrapperFields__changeFields").append(partial);

return this;
}

关于javascript - 下划线模板(二合一)/Backbone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16404597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com