数组片断返回[对象对象],而不是价值 [英] Array Slice Returning [object Object] instead of value

查看:167
本文介绍了数组片断返回[对象对象],而不是价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当它降到获取特定div的位置。随着一些帮助,我有放在一起code波纹管。我是最后一位加入到尝试并获得具体数值,但它只是返回,而不是像[对象的对象] [0,0]或[0,120]

所以,问题是我如何从阵列获取的实际值?

这里是一个的jsfiddle

  $(函数(){
    $('。APPLIST')。可弃({
        接受:.APP
        宽容:适应,
        下降:函数(事件,UI){
            VAR应用= $(应用程序),
            位置= [];            $。每个(应用程序,功能(索引,应用程序){
                变种positionInfo = $(应用).POSITION();                positions.push(positionInfo);
            });
            无功时间= positions.slice(0,1);
            变种X =的document.getElementById(posThis);
            x.innerHTML =时间;
            的console.log(职位);
        }
    });
});


解决方案

这里的问题是, positionInfo 是一个对象,而不是一个数组。 时间是里面一个这样的对象数组。

我相信你想要的东西是这样的:

  VAR时间=位置[0];
变种X =的document.getElementById(posThis);
x.innerHTML ='['+ Time.left +','+ Time.top +']';

I am trying to get the position of a specific div when it is dropped. With some help i have put together the code bellow. I added in the last bit to try and get the specific values but it simply returns [object Object] instead of something like [0,0] or [0,120].

So the question is how do i get the actual values from the array?

Here is a jsFiddle

$(function() {
    $('.AppList').droppable({
        accept: ".App",
        tolerance: 'fit',
        drop: function(event, ui) {
            var apps = $(".App"),
            positions = [];

            $.each(apps, function (index, app) {
                var positionInfo = $(app).position();

                positions.push(positionInfo);
            });
            var Time = positions.slice(0,1);
            var x=document.getElementById("posThis");
            x.innerHTML=Time;
            console.log(positions);
        }
    }); 
});

解决方案

The problem here is that positionInfo is an object, not an array. Time is an array with one such object inside.

I believe you want something like this:

var Time = positions[0];
var x=document.getElementById("posThis");
x.innerHTML= '[' + Time.left + ',' + Time.top + ']';

这篇关于数组片断返回[对象对象],而不是价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆