通过 jquery 触发器传递对象

发布于 2024-09-18 19:32:50 字数 480 浏览 2 评论 0原文

我正在尝试做一些相当简单的事情,但得到了一个奇怪的结果。我有一个事件触发器,我用它来传递 json 对象,但是当它到达另一端时,它是一个函数...我警告结果,它显示以下内容:

警报刺痛的示例:

alert('value of lattitude? ' + map.currentLatLng.lat);

结果:

纬度值?函数() {返回this[a];}

我尝试过使用和不使用数组文字包装器来设置触发器:

$('body').trigger('updateLocation', [{lat:38.905003, lng:-77.066497}]);
$('body').trigger('updateLocation', {lat:38.905003, lng:-77.066497});

我做错了什么?

I'm trying to do something rather simple but I'm getting a strange result. I have an event trigger that I'm using to pass a json object but when it gets through to the other side it's a function... I alert the result and it shows this:

example of alert sting:

alert('value of lattitude? ' + map.currentLatLng.lat);

result:

value of lattitude? function () {return this[a];}

I've tried setting up the trigger both with and without the array literal wrapper:

$('body').trigger('updateLocation', [{lat:38.905003, lng:-77.066497}]);
$('body').trigger('updateLocation', {lat:38.905003, lng:-77.066497});

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2024-09-25 19:32:50

试试这个:

$('body').bind('updateLocation',function(event,obj){
    alert(obj.lng);
});

$('body').trigger('updateLocation', [{lat:38.905003,lng:-77.066497}]);

Try this:

$('body').bind('updateLocation',function(event,obj){
    alert(obj.lng);
});

$('body').trigger('updateLocation', [{lat:38.905003,lng:-77.066497}]);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文