javascript - Why wont this return the image from an object to display the image in html? -
updated code & image
it looks images each of returned objects in query "undefined"
parse.com , javascript.
i've managed code return object want, want take out "pic" url can show on html page.
i've looked, struggle see examples of how pull out attributes of class.
the below shows approach, thats returning bad url shown in screen shot.
what have done wrong here?
var currentuser = parse.user.current(); var friendrequest = parse.object.extend("friendrequest"); var query = new parse.query(friendrequest); query.include('touser'); query.equalto("fromuser", currentuser); query.equalto("status", "request sent"); //query.exists("pic"); query.find({ success: function(results) { // if query successful, store each image url in array of image url's imageurls = []; (var = 0; < results.length; i++) { var object = results[i]; imageurls.push(object.get('pic')); } // if imageurls array has items in it, set src of img element first url in array for(var j = 0; j < imageurls.length; j++){ $('#imgs').append("<img src='" + imageurls[j] + "'/>"); } }, error: function(error) { // if query unsuccessful, report errors alert("error: " + error.code + " " + error.message); } }); // show signup or login page </script> <div id="imgs"></div>
descend stack using "get()" have object in :
results[0].get("touser").pic
instead of :
results[0].touser.pic
in pic of debugger, type of results.0.touser "object".
i dont think reference object without using javascript
.get(myobject)
since not using framework (setting collection , model make easy ) encapsulates specifics of parseing response , have hand , making sure each step descend done have valid reference/type child.
the reason have undefined results.0.touser.pic you've not done parse correctly.
Comments
Post a Comment