在javascript中我想将两个对象合并为一个.我有
{
test: false,
test2: false
}
Run Code Online (Sandbox Code Playgroud)
和
{
test2: true
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用$.extend,$.merge但我得到的只是输出
{
test2: true
}
Run Code Online (Sandbox Code Playgroud)
如何获得这样的输出
{
test: false,
test2: true
}
Run Code Online (Sandbox Code Playgroud)
编辑:其实我有嵌套对象.我需要的是结合a和b如下:
var a = { test: false, test2: { test3: false, test4: false } };
var b = { test2: { test4: true } };
// desired combined result:
{ test: false, test2: { test3: false, test4: true } }
Run Code Online (Sandbox Code Playgroud)
但是我得到的实际结果是test3从嵌套test2对象中删除的.
我从谷歌获得了这个修改过的示例代码
var stockholm = new google.maps.LatLng(59.32522, 18.07002);
var parliament = new google.maps.LatLng(59.327383, 18.06747);
var marker;
var map;
function initialize() {
var mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: stockholm
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: parliament,
icon: '/img/marker.png'
});
google.maps.event.addListener(marker, 'click', toggleBounce);
setTimeout(function() { marker.setAnimation(google.maps.Animation.BOUNCE); }, 2000);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道在DROP动画停止后是否可以将标记动画从DROP更改为BOUNCE?
我设法使用setTimeout()函数更改它,但它没有顺利完成.任何帮助将不胜感激.