I have a collection with 25 fields. When a query retrieves a number of items, I only need a few things such as name and address out of each item. Is there a routine that will do this without having to write an ugly parser?
Thanks in advance.
Can you please show me the code through which you retrieving data from database?
Sure - thanks, Umair.
export function button13_click(event) {
//Add your code for this event here:
wixData.query(“Reginfo2020”)
.eq(“totalCost”, “25”)
.ascending(“lastName”)
.limit(15)
.find()
.then( (results) => {
let res = results.items[0];
console.log(res);
console.log(res[0].fieldKey[“lasttName”]);
//The following doesn’t work…
//$w(“#queryResult”).text = res[0].“lastName”;
});
}
The query result from console.log is:
{…}
"Bend"city:
"25"totalCost:
"pglick@bendcable.com"email:
"Flavor 1"sessionC:
“01b5f762-427e-41f7-a1dd-1b54429be259”_id:
“0e34b854-1245-4212-a1fd-147f4ae50d11”_owner:
“2019-11-14T22:45:29.867Z”_createdDate:
"20"costIndivClasses:
“2019-11-14T22:45:29.867Z”_updatedDate:
"Meal 4"sessionD:
"Glick"lastName:
"Pete"firstName:
""howDid:
""sessionA:
"0"buffetLunch:
""sessionB:
"11/14/2019 2:45:29 PM"dateAndTime:
"5"miniGarden:
"2"numIndivClasses:
"0"growingHardy:
"5413306260"phone:
"0"allDayPackage:
"/reginfo-2020/RegRepeater"link-reginfo-2020-RegRepeater-all:
Please use this one if you want to get the last name of the first item in your query result
replace this line let res = results.items[0]
with this let res = results.items[0].lastName;
and remove this one console.log(res[0].fieldKey[“lasttName”]);
It will work for you.
Thank you, Umair! You are a lifesaver.
@tumalopete My pleasure buddy