假设有三个对象,note、noteState 和 history:
var note = {
text: "hello new world"
}
var history = {}
var noteState = {}
我怎样才能将笔记添加到 noteState,然后将 noteState 添加到历史记录?
我可以做类似的事情吗:
$.extend(noteState, {"note1": note});
$.extend(history, {"noteState1": noteState});
如果我要回头引用它以从笔记中获取文本,我将如何去做?
history.noteState1.note1.text // ?
或者有其他方法可以解决这个问题吗?谢谢!
最佳答案
你为什么不简单
var note = {
text: "hello new world"
}
var history = {}
var noteState = {}
noteState.note = note;
history.noteState= noteState;
alert(history.noteState.note.text);//alerts hello new world
关于javascript - 将对象添加到另一个对象中的另一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9307450/