Mootools从每个人获得第一个价值

时间:2013-03-22 13:09:13

标签: php ajax json mootools

我有一张来自Json的数组图片:

images=JSON.decode(images);

这是数组值:

[
    {
        "title": "",
        "description": "",
        "name": "loc commerciale.jpg"
    },
    {
        "title": "",
        "description": "",
        "name": "foto2.jpg"
    },
    {
        "title": "",
        "description": "",
        "name": "foto 1.jpg"
    },
    {
        "title": "",
        "description": "",
        "name": "a01.jpg"
    }
]

我从名称中获取值:

images.each(function(image){                
    alert(image.name);
});

我只需要获得第一个值名称

喜欢php:

$images = (array) json_decode($row->images);
$first = true;
foreach ($images as $k => $image) {
    if ($first)
    {
        $firstimage= $image->name;
        $first = false;
    }
}

1 个答案:

答案 0 :(得分:0)

尝试:

if (images[0].length){
    var firstImageName = images[0].name;
}
相关问题