Специально, массив возвращается из API в следующем формате: < /p>
//PHP
$returnInfo[] = array("success"=>true,"reviews"=>$reviews,"iCount"=>$resCount) ;
//...
sendResponse(200, json_encode($returnInfo));
< /code>
Код: Выделить всё
//JS
service.getReviews
.then(function(response) {
let resData = response.data ;
console.log(resData) ;
// prints to console
//
// [{…}]
// 0:
// iCount: 0
// > reviews: (3) [{…}, {…}, {…}]
// success: true
// > [[Prototype]]: Object
// length: 1
// > [[Prototype]]: Array(0)
//
var allReviews = null ;
if (resData.iCount == 0) {
allReviews = resData.reviews ;
}
< /code>
Мое ожидание состоит в том, что это принесло бы ошибку, потому что на нее следует ссылаться как: < /p>
var allReviews = null ;
if (resData[0].iCount == 0) {
allReviews = resData[0].reviews ;
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -an-object
Мобильная версия