javascript - Clearing JS response -
i making call api. api returns list of results. when - response fed object use iterate through , display them.
here function that:
var getavailability = () => { if (chosendata.hotel == "") { showerror("please select location before booking."); $timeout(() => ltbnavservice.settab('location'), 50); return; } searchresponse = {}; console.log(searchresponse); webapi.gethotelavailability(gensearchobject()).then((data) => { searchresponse = data; $timeout(() => $('[data-tab-content] .search-btn').first().focus(), 50); generateroomtypeobject(searchresponse); }, (data) => searchresponse.error = data.data.errors[0].error); };
the problem: old results still displayed until new set of results available. causes flicker , delay bad user experience.
the solution:(which need with) best possible way of handling problem? ideally, reset/clear search response. in, new results delivered , old ones cleared. possible within getavailability function?
what best way achieve this?
the solution:
thanks @daniel beck suggestion call generateroomtypeobject function , feed empty object - +1'd comment.
this triggered undefined error in generateroomtypeobject function running few length checks(makes sense, because object empty - there nothing length checks on).
i handled error handling undefined exception , setting searchresponse empty object.
var generateroomtypeobject = (searchresponse) => { var rateplans = searchresponse.rateplans, errors = searchresponse.error, roomtypes = [], ignorebiggerrooms = false; rawroomsobjs = []; if (angular.isundefined(errors)) { // iterate on rate plan if(rateplans === undefined){ //generateroomtypeobject -- handle undefined creating new object searchresponse = {} }else{ (var = 0; < rateplans.length; i++) { var rateplan = rateplans[i], rooms = rateplan.rooms; // iterate on rooms , add rooms room object. keep list of room types. (var j = 0; j < rooms.length; j++) { //stuff here } } } }
Comments
Post a Comment