查询返回控制台日志中的项目,但是html显示Uncaught TypeError: Cannot call method

Query returns items in console log, but html is showing Uncaught TypeError: Cannot call method 'get' of undefined when trying to display on the page

本文关键字:TypeError Uncaught 显示 Cannot method call html 但是 日志 控制台 返回      更新时间:2023-09-26

Parse.com和JavaScript SDK。

代码查询并返回结果,然后应该显示在id "imgs"中。现在我得到一个

Uncaught TypeError: Cannot call method 'get' of undefined

错误。我试过了,但不明白是什么原因造成的或如何解决它。

页面的url在这里http://kudosoo.com/friendslistTEST.html

把我逼疯了

var currentUser = Parse.User.current();  
var FriendRequest = Parse.Object.extend("FriendRequest");

    var query = new Parse.Query(FriendRequest);
    query.include('toUser');
   // query.include('fromUser');
    //query.include('pic');
    query.equalTo("fromUser", currentUser);
    query.equalTo("status", "Request sent");
         query.find({
              success: function(results) {
        // If the query is successful, store each image URL in an array of image URL's
        imageURLs = [];
        for (var i = 0; i < results.length; i++) { 
          var object = results[i];
          imageURLs.push(object.get('pic'));
        }
     // If the imageURLs array has items in it, set the src of an IMG element to the first URL in the array
        for(var j = 0; j < imageURLs.length; j++){
           $('#imgs').append("<img src='" + imageURLs[j].get("toUser").pic + "'/>");                 
        }
      },
      error: function(error) {
        // If the query is unsuccessful, report any errors
        alert("Error: " + error.code + " " + error.message);
      }
    });
         // show the signup or login page
 </script>
<div id="imgs"></div>

使用。

imageURLs = [];
        for (var i = 0; i < results.length; i++) { 
          var object = results[i].get("toUser");
         imageURLs.push(object.get("pic"));
        }
     // If the imageURLs array has items in it, set the src of an IMG element to the first URL in the array
        console.log(imageURLs);
        for(var j = 0; j < imageURLs.length; j++){
          $('#imgs').append("<img src='" + imageURLs[j] + "'/>");               
        }