javascript - Selecting item2 on page 1 returns item1 on page2 -
i dynamically creating rows , tables database display list of read-only items. when 1 of these items clicked, page should reload different window , display relevant results related clicked item.
i have 99% of working, when click first row (let's "item1" next window reflects undefined. when click second row ("item2") window reflects results of item1. when click third row ("item3") window reflects results of item2.
the understand may not storing variables correctly.
my closest guess may solution querystring, not sure how or implement it.
i have provided relevant code commented sake of else may have problem.
var customapp = function(){ // establish variables var salonname var salondomainlink var salonaddress var salonphonenumber var salonselection // queries salons class var query1 = new parse.query("salons"); query1.find({ success: function(results) { // changes search results json object ?something readable? var searchresults = json.parse(json.stringify(results)) // loops through every result , creates variables each specific result ( var in searchresults) { salonname = searchresults[i].name; salondomainlink = searchresults[i].domainlink; // creates new row each item in table var newrow = $('<tr>').text('').appendto('#searchtable'); // adds cell each salonname in row var namecell = $('<td>').text(salonname).appendto(newrow); // adds id of salon name + 'id' each row var cellid = namecell.attr("id", salonname.replace(/\s+/g, '') + "id") // changes class of each cell namecell.addclass("text-left font-w600 text-primary"); } // passes clicked salon name variable use on page $('#searchtable tr td').click(function(){ // acquires text value of specific td of tr salonselection = $(this)[0].childnodes[0].nodevalue // saves variable local storage (can retrieved "localstorage.salonselection") delete localstorage.salonselection; window.localstorage.salonselection = salonselection; window.location = 'base_pages_schedule_1.html'; }); }, error: function(error) { alert("error: " + error.code + " " + error.message + ". please contact support."); } }); query1.equalto("name", localstorage.salonselection); query1.find({ success: function(results) { var searchresults = json.parse(json.stringify(results)) // loops through every result , creates variables each specific result ( var in searchresults) { window.localstorage.salonname = searchresults[i].name; window.localstorage.salondomainlink = searchresults[i].domainlink; window.localstorage.salonaddress = searchresults[i].address; window.localstorage.salonphonenumber = searchresults[i].phonenumber; } }, error: function(error) { alert("error: " + error.code + " " + error.message + ". please contact support."); } }); $('#salon-name').text(localstorage.salonname); $('#salon-address').text(localstorage.salonaddress); $('#salon-phone-number').text(localstorage.salonphonenumber):};
query.find() asynchronous won't set new values until after set text() in dom
move dom updates find() success callback
query1.find({ success: function(results) { var searchresults = json.parse(json.stringify(results)) // process results // update dom $('#salon-name').text(localstorage.salonname); }, error: function(error) { alert("error: " + error.code + " " + error.message + ". please contact support."); } }); also note for loop rewriting new value storage keys on each iteration of loop last 1 gets stored. not sure storage objectives here
Comments
Post a Comment