jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 当在backbone.js中查看视图时为什么要渲染额外的div大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么在BACkbone.js中查看视图时会渲染额外的div

BACkbone.View.extend({
  template :_.template( 
        '<li id="user-<%=user.username%>" class="pp-entry group">'+
            '<img src="i/pp-pic-1.png" class="pp-pic" alt="" />'+
            '<span class="whisper-mode-on hide" title="Whisper mode on"></span>'+
            '<h6 class="pp-name"><%=user.firstname%>&nbsp; <%if(user.lastname!="null"){%><%=user.lastname%><%}%></h6>'+
            '<p id="chat-<%=user.username%>"class="pp-msg"></p>'+
        '</li>'),initialize: function() {
    _.bindAll(this,'render','close');
    this.model.bind('change',this.render);
    this.model.view = this;
  },// Re-render the contents of the User item.
  render: function() {
    $(this.el).html(this.template(this.model.toJSON()));

                $("#participant-window").prepend(this.el);
}
});

什么时候它正在渲染它像这样:

<ul id="participant-window" class="scroll-pane" style="overflow: hidden; padding: 0px; width: 357px;">
<div>
<li id="user-ashutosh" class="pp-entry group" style="cursor: default;">
<img class="pp-pic" alt="" src="i/pp-pic-1.png">
<span class="whisper-mode-on hide" title="Whisper mode on"></span>
<h6 class="pp-name">Ashutosh&nbsp; </h6>
<p id="chat-ashutosh" class="pp-msg"></p>
</li>
</div>
</ul>

为什么li插入div我应该如何阻止它?

解决方法

在这一行:

$(this.el).html(this.template(this.model.toJSON()));

…您将this.el的内容设置为模板输出.如果某个el成员变量已经初始化为现有的div元素,那么你只需更改它的内容,然后附加到#reference-window.

也许试试:

this.el = $(this.template(this.model.toJSON())));

大佬总结

以上是大佬教程为你收集整理的jquery – 当在backbone.js中查看视图时为什么要渲染额外的div全部内容,希望文章能够帮你解决jquery – 当在backbone.js中查看视图时为什么要渲染额外的div所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。