var obj = {
customerInfo: {
fname: "Tom",
lname: "Smith",
age: 23,
height: 160
},
car: {
color: "red",
numWheels: 4
}
};
我想修改這個對象爲:使用下劃線_.extend以避免覆蓋嵌套對象?
var obj = {
customerInfo: {
fname: "Sally",
lname: "Adams",
mname: "Tully",
age: 23,
height: 160
},
car: {
color: "red",
numWheels: 4
}
};
但是,如果我這樣做
_.extend(obj, {
customerInfo: {
fname: "Sally",
lname: "Adams",
mname: "Tully"
}
});
的對象變成
{
customerInfo: {
fname: "Sally",
lname: "Adams",
mname: "Tully"
},
car: {
color: "red",
numWheels: 4
}
};
和年齡和身高已被清除。
我需要做些什麼來保留嵌套的數據?
那麼更新更復雜的對象呢?
http://jsfiddle.net/j4L18p7k/2/#share
感謝。我的例子太簡單了。有更好的更快的方法來更新更復雜的對象,比如我的例子嗎? http://jsfiddle.net/j4L18p7k/2/#share也添加到OP中。 – fuzzybabybunny