私はバックボーンjsに不慣れで、私の最初のやりとりはかなり複雑なようです。問題はこのようになります
私はこのようなモデルを作りました
window.Dir = Backbone.Model.extend({
defaults: {
"Name": "",
"ChildNodes": new window.FSNodeCollection() },
GetFullName: function () { this.get("id"); }
});
window.FSNodeCollection
私が作った他のコレクションです。new window.FSNodeCollection()
お気づきのように、私が読んだ内容に応じてChildNodes
window.FSNodeCollection()
、ChildNodes属性の値をこれに設定しました
が、このモデルを使用する場合は、の値を新しいものに設定する必要があります。
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
に追加されていますが、ChildNodes
fsNode
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)
問題はもう残っていません。