Cannot get the value of database

Hi, I would like to get the price of database and add “$” in front of the price.
The price data type is number and the field name is “Price”.

The code are below:

import wixData from ‘wix-data’;

$w.onReady( function () {

let price_text = $w(“#dataset1”).getCurrentItemIndex().Price;
$w(‘text5’).text = “$” + price_text;
});

The log is
TypeError: Cannot ead propetty ‘Price’ of null

The problem is most likely that the dataset is not yet ready and therefore no item is returned. You should use the dataset onReady() function. Something like this:

import wixData from 'wix-data';

$w.onReady(function () {
   $w("#dataset1").onReady( () => {
      let price_text = $w("#dataset1").getCurrentItemIndex().price;
      $w('#text5').text = "$" + price_text;
   });
});

Also note the following:

  • You need to use the field key (price) and not the field name (Price).

  • An element ID uses a hashtag. It is #text5 and not text5.

Good luck,

Yisrael