抱歉标题含糊不清,我不确定发生了什么足以更好地制定它。
所以,这是我认为的渲染:
render: function () {
var that = this;
var template = JST['gists/index'];
that.$el.html(template);
console.log(['index to render', that.collection]);
_.each(that.collection, function (gist) { // <- I set a breakpoint here
console.log('looping');
that.appendGistDetail(gist);
});
return that;
},
`console.log(..., that.collection]) 正在正确记录此集合:
["index to render", child]
0: "index to render"
1: child
_byId: Object
length: 1
models: Array[1] // <- Note one element. Saving space, but I checked it out and the model is correct
// Worth noting 'looping' is not being logged
然而,前面提到的断点作用域变量的输出显示在 Chrome 开发工具中:
that: child
$el: jQuery.fn.jQuery.init[1]
childViews: Array[0]
cid: "view2"
collection: child
_byId: Object
length: 0
models: Array[0] // <- Note it's empty, just to test I also set a bp on the line above and it's the same, and when I hovered my mouse over `that.collection` from `console.log` it also said it was empty, but it logs correctly.
所以,我真的不知道该怎么做,甚至不知道发生了什么。