几天前,我被 Javascript 的关闭错误严重咬伤,但太忙没时间问。我正在尝试使用jQuery
模板引擎进行以下操作。
<ul id="container"></ul>
<script type="text/jq-tmpl" id="myTmpl">
<li>
<span style="background:#fafafa">X:${X}</span>
<span style="background:#ababab">Y:${Inner.Y}</span>
<span style="background:#9a9a9a">Z:${Inner.Z}</span>
</li>
</script>
function OuterObject(x,y,z){
this.X = x;
this.Inner = InnerObject(y,z);
}
function InnerObject(y,z){
this.Y=y;
this.Z=z;
}
$(function(){
var l=[];
l.push(OuterObject(1,"One","inner-1"));
l.push(OuterObject(2,"Two","inner-2"));
$("#myTmpl").tmpl(l).appendTo("#container");
});
问题是它显示inner-2
了Two
两个项目。我也试过这样:
var a=OuterObject(1,"One","inner-1");
l.push(a);
var b=OuterObject(2,"Two","inner-2");
l.push(b);
但是都是一样的。