Javascript从多维数组中获取值

Javascript从多维数组中获取值,javascript,arrays,multidimensional-array,Javascript,Arrays,Multidimensional Array,我遇到了从数组中获取值的问题。由于某些原因,我无法使其工作(仅获取[object]),并感谢您在此提供的任何帮助: 我在这里创建响应 foreach ($locations as $location) { if($location->getStreet1() != ''){ $result .= $location->getStreet1() .', '; } if($location->getCi

我遇到了从数组中获取值的问题。由于某些原因,我无法使其工作(仅获取[object]),并感谢您在此提供的任何帮助:

我在这里创建响应

    foreach ($locations as $location) {
        if($location->getStreet1() != ''){
            $result .= $location->getStreet1() .', ';
        }
        if($location->getCity() != ''){
            $result .= $location->getCity() .', ';
        }
        $locationList[$i]['location'] = addslashes(htmlspecialchars($location->getName()));
        $locationList[$i]['address'] = addslashes(htmlspecialchars($result));
        $i++;
        $result = '';
    }
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode(array('locations' => $locationList)));
在这里,我正在处理回应:

                        request.done(function(data) {

                            var container = jQuery('#hotel-list-container');
                            var locations = jQuery.parseJSON(data).locations;

                            container.html('');
                            var firstSymbols = [];

                            locations.forEach(function(location) {
                                var firstSymbol = location.location;

                                if (jQuery.inArray(firstSymbol, firstSymbols) === -1) {
                                    firstSymbols.push(firstSymbol);
                                }
                            });

                            firstSymbols.forEach(function(firstSymbol) {
                                if (jQuery.isNumeric(firstSymbol)) {
                                    if (container.find('.numeric').size() === 0) {
                                        container.append('<div class="numeric">0&ndash;9</div>');
                                    }
                                } else {
                                    container.append('<div class="letter">' + firstSymbol + '</div>');
                                }

                                locations.forEach(function(data) {
                                    if (firstSymbol == data.location) {
                                        container.append('<div class="hotel-item"><a class="hotel" data-id="' + data.location + '"><div class="hotel_addr_div"><span>' + data.location +'</span>'+data.address+'</div></a></div>');
                                        console.log(data.location);
                                    }
                                });
                            });
                            container.slideDown(null, function() {
                                jQuery('#hotel-list-container').mCustomScrollbar({ scrollInertia: 0 });
                            });
                        });


locations.forEach(function(data) {
    if (firstSymbol == data.location) {
        container.append('<div class="hotel-item">
            <a class="hotel" data-id="' + data.location + '">
                <div class="hotel_div"><span>' + data.location +'</span>'+data.address+'</div>
            </a>
        </div>');
                                     }
request.done(函数(数据){
var container=jQuery(“#酒店列表容器”);
var locations=jQuery.parseJSON(data.locations);
container.html(“”);
var firstSymbols=[];
位置。forEach(函数(位置){
var firstSymbol=location.location;
if(jQuery.inArray(firstSymbol,firstSymbols)=-1){
firstSymbol.push(firstSymbol);
}
});
firstSymbols.forEach(函数(firstSymbol){
if(jQuery.isNumeric(firstSymbol)){
if(container.find('.numeric').size()==0){
container.append('0&ndash;9');
}
}否则{
container.append(“”+firstSymbol+“”);
}
位置。forEach(函数(数据){
if(firstSymbol==data.location){
container.append(“”+data.location+“”+data.address+“”);
console.log(数据位置);
}
});
});
container.slideDown(null,function()){
jQuery(“#hotel list container”).mCustomScrollbar({scrollInertia:0});
});
});
位置。forEach(函数(数据){
if(firstSymbol==data.location){
container.append('
'+data.location+''+data.address+'
');
}
这就是我在前端看到的

<div class="hotel-lists" id="hotel-list-container-mobile" style="max-height: 497px;">
    <div class="letter">undefined</div>
    <div class="hotel-item"><a class="hotel" data-id="[object Object]">[object Object]</a></div>
    <div class="hotel-item"><a class="hotel" data-id="[object Object]">[object Object]</a></div>
    <div class="hotel-item"><a class="hotel" data-id="[object Object]">[object Object]</a></div>
</div>

未定义
[对象]
[对象]
[对象]

谢谢您的所有回答。如请求,我在这里添加了完整的代码

您的javascript代码看起来与前端不一致:javascript将类定义为
酒店
,但前端说类是
酒店项目
。不,
酒店
是内部的
标记。请从
数据添加一些数据de>。您可以执行
控制台.log(位置)
?JS代码和HTML不匹配(不同的容器id,不同的链接格式)。请确保提供一致的数据。您的javascript代码看起来与前端不一致:javascript将类定义为
酒店
,但前端说类是
酒店项目
。不,
酒店
是内部的
标记。请从
数据
添加一些数据。您可以执行
控制台.log(位置)吗
?JS代码和HTML不匹配(不同的容器id、不同的链接格式)。请确保提供一致的数据。