Javascript 下划线模板无法生成TD元素
我对underline.js模板有一个非常奇怪的问题。在除IE9之外的所有浏览器中,我使用的模板都会按设计生成HTML标记,但在IE9中则不会。以下是模板:Javascript 下划线模板无法生成TD元素,javascript,jquery,templates,backbone.js,underscore.js,Javascript,Jquery,Templates,Backbone.js,Underscore.js,我对underline.js模板有一个非常奇怪的问题。在除IE9之外的所有浏览器中,我使用的模板都会按设计生成HTML标记,但在IE9中则不会。以下是模板: , manageColumnsTableTemplate: _.template( '<td class="padss-glyphs">▣</td>' + '<td><input type="text" size="1" data-key="<%=ID%>" name="sort" va
, manageColumnsTableTemplate: _.template(
'<td class="padss-glyphs">▣</td>' +
'<td><input type="text" size="1" data-key="<%=ID%>" name="sort" value="<%=SortOrder%>" /> <a class="up" data-key="<%=ID%>" data-sort="<%=SortOrder%>">up</a> <a class="down" data-key="<%=ID%>" data-sort="<%=SortOrder%>">down</a></td>' +
'<td><input type="checkbox" data-key="<%=ID%>" <% if(Display) {%>checked="checked" <%}%> /></td>' +
'<td><%=Value%></td>')
这真的让我们难堪,任何帮助都将不胜感激
谢谢
迈克
有人建议在ColumnDisplayView.js中将标记名更改为标记名可以解决此问题。这根本没有影响它。以下是一些控制台输出:
>> __p
"<td class="padss-glyphs">▣</td><td><input type="text" size="1" data-key="11" name="sort" value="3" /> <a class="up" data-key="11" data-sort="3">up</a> <a class="down" data-key="11" data-sort="3">down</a></td>
<td><input type="checkbox" data-key="11" checked="checked" /></td>
<td>LEVEL</td>"
el.tagName是TR,因此添加uz.template()输出应该可以
>> this.el.innerHTML
"▣<input name="sort" value="3" size="1" type="text" data-key="11"> <a class="up" data-key="11" data-sort="3">up</a> <a class="down" data-key="11" data-sort="3">down</a>
<input CHECKED="checked" type="checkbox" data-key="11">
LEVEL"
>this.el.innerHTML
"▣ 上下
级别“
当将uu.template()输出分配给el.innerHTML时,TD标记将被剥离。您应该在ColumnDisplayView.js中将
标记名
替换为标记名
,感谢一月的回复。我最终通过使用jQuery设置元素的内部html解决了这个问题。下面是有效的代码
define([
'modules/PadssView'
], function (PadssView) {
return PadssView.extend({
tagName: 'tr',
initialize: function () {
var html;
if (typeof this.model.toJSON !== 'undefined') {
html = PADSS.manageColumnsTableTemplate(this.model.toJSON());
} else {
//not a model... coming in from the new preferences it seems
this.model.ID = this.model.id;
this.model.Display = this.model.visible;
this.model.SortOrder = this.model.order;
html = PADSS.manageColumnsTableTemplate(this.model);
}
$(this.el).html(html);
return this;
}
});
});
正如我前面提到的,u.template()工作得很好。当模板输出直接分配给this.el.innerHTML时,TD元素被剥离。我不确定问题是什么,但这绕过了它
谢谢,
迈克我试着再现你描述的问题,但我就是做不到。可能是因为ColumnDisplayView.js中的“标记名”是用小写字母写的吗?@Jan:听起来很像。这将使
这个.el
成为
,而将
直接放在
中是无效的HTML,即可以通过剥离
来“纠正”它。您可能希望将您的评论转换为答案。正如我之前所写的,我无法重现您的问题-除非我将您从u.template返回的字符串放在无效的位置(而不是TR中)。
define([
'modules/PadssView'
], function (PadssView) {
return PadssView.extend({
tagname: 'tr',
initialize: function () {
if (typeof this.model.toJSON !== 'undefined') {
this.el.innerHTML = PADSS.manageColumnsTableTemplate(this.model.toJSON());
} else {
//not a model... coming in from the new preferences it seems
this.model.ID = this.model.id;
this.model.Display = this.model.visible;
this.model.SortOrder = this.model.order;
this.el.innerHTML = PADSS.manageColumnsTableTemplate(this.model);
}
return this;
}
});
});
>> __p
"<td class="padss-glyphs">▣</td><td><input type="text" size="1" data-key="11" name="sort" value="3" /> <a class="up" data-key="11" data-sort="3">up</a> <a class="down" data-key="11" data-sort="3">down</a></td>
<td><input type="checkbox" data-key="11" checked="checked" /></td>
<td>LEVEL</td>"
>> this.el.tagName
"TR"
>> this.el.innerHTML
"▣<input name="sort" value="3" size="1" type="text" data-key="11"> <a class="up" data-key="11" data-sort="3">up</a> <a class="down" data-key="11" data-sort="3">down</a>
<input CHECKED="checked" type="checkbox" data-key="11">
LEVEL"
define([
'modules/PadssView'
], function (PadssView) {
return PadssView.extend({
tagName: 'tr',
initialize: function () {
var html;
if (typeof this.model.toJSON !== 'undefined') {
html = PADSS.manageColumnsTableTemplate(this.model.toJSON());
} else {
//not a model... coming in from the new preferences it seems
this.model.ID = this.model.id;
this.model.Display = this.model.visible;
this.model.SortOrder = this.model.order;
html = PADSS.manageColumnsTableTemplate(this.model);
}
$(this.el).html(html);
return this;
}
});
});