WixData.get()

Hi, I need help
How to get data just for qty 1 item collection ?
Example :
Item A : 100 qty
Item B : 50 qty

Thanks for sharing


Hello.

Kindly note that wixData.get() function returns 1 item by default since you need to specify item ID, which is unique.

Assuming you wish to return only an item whose quantity field value is 1, then you can us eq property of wixData.query() :

wixData.query("myCollection")
.eq("qty", 1)

If you wish to return just one item, then you can set our query results limit:

wixData.query("myCollection")
  .limit(1)

Should you need further assistance, please follow the guidelines here:Guidelines for Posting to the Corvid Forum

Hai thx for reply,
In my code, what is item ID ?

wixData.get(“Ticket”, “??”)
.then ((result) => {
$w(‘#text8’).text = result.toString()
})

Thanks for sharing

Dear Our Story,

Using “wixData.get” only one data will be dispatched onto your TextBox.

For that:

  1. Create a Dropdown with the “_id” as value from your collection.
  2. To set up the Labels and the Values (_id) for your Dropdown, please use the code #1
  3. On change of Dropdown, use the function “change” code #2

Hope this helped you.
Best regards
Domivax

CODE #1
let GetCollectionId = ;

$w.onReady( async function () {

let ResultGetCollectionId = await wixData.query( "MyCollection ).ascending( " FieldSort1 " , “FieldSort2” ).limit( 100 ).find();
let ResultGetCollectionIdItems = ResultGetCollectionId.items;
GetCollectionId = ResultGetCollectionIdItems.map((item) => { return { “label” : item.title, “value” : item._id } });

$w( '#DropdownPickUpId' ).options = GetCollectionId; 

})

//item._id will be used to get the data

CODE #2
export function DropdownPickUpId_change(event) {
wixData.get( " MyCollection " , $w( ‘#DropdownPickUpId’ ).value)

.then( (results) => {
let item = results; //see item below
$w( ‘#TextFinalResult’ ).text = results.title
})

}