im對於骨幹js來說我是新的,我的第一個交互看起來很完美。問題是這樣的
我做了一個模型,這樣在「defaults」中提供新的集合backbone.js
window.Dir = Backbone.Model.extend({
defaults: {
"Name": "",
"ChildNodes": new window.FSNodeCollection() },
GetFullName: function() { this.get("id"); }
});
window.FSNodeCollection
的是,我已經取得了一些其他集合。 ,你會發現我已經把的childNodes的屬性的值new window.FSNodeCollection()
這個據我已閱讀應的ChildNodes
值設置爲一個新的window.FSNodeCollection()
但在使用這種模式的IM一樣
var fsNode = new window.FSNode({
Type: "dir",
Node: new window.Dir({
Name: "dir1",
})
});
var fsNode2 = new window.FSNode({
Type: "dir",
Node: new window.Dir({
Name: "dir2",
})
});
var subDir1Node = new window.FSNode({
Type: "dir",
Node: new window.Dir({
Name: "subDir1",
ChildNodes:new window.FSNodeCollection()
})
});
fsNode.get("Node").get("ChildNodes").push(subDir1Node);
的subDir1Node
被添加到兩個fsNode
的ChildNodes
和fsNode2
我做錯了什麼?
當我嘗試做這樣的事情
var fsNode = new window.FSNode({
Type: "dir",
Node: new window.Dir({
Name: "dir1",
ChildNodes:new window.FSNodeCollection()
})
});
var fsNode2 = new window.FSNode({
Type: "dir",
Node: new window.Dir({
Name: "dir2",
ChildNodes:new window.FSNodeCollection()
})
});
var subDir1Node = new window.FSNode({
Type: "dir",
Node: new window.Dir({
Name: "subDir1",
ChildNodes:new window.FSNodeCollection()
})
});
fsNode.get("Node").get("ChildNodes").push(subDir1Node)
問題仍然沒有更多的。
是的,我不認爲這是好主意,宣佈'指向'Object' Model.attributes'鍵秒。 – fguillen
事情有時是backbone.js構造你的代碼的方式,很容易忘記它仍然是JavaScript,並且繼承在其他語言中並不像其它語言那樣工作。 – Jack