.getCurrentItem() Issue

I am working on a site for a customer and it seems that the .getCurrentItem() does not work when using a collection/dataset. All other items in the repeater seem to be working fine, but the text element that I am trying to pull in dynamically doesn’t come in. I assume it’s because of the .getCurrentItem().

I followed the tutorial here: https://support.wix.com/en/article/corvid-tutorial-creating-a-show-more-link

Any suggestions or recommendations that would allow me to get the .bio text from each record in my collection and not just the first one?

Here is my code:

$w.onReady( () => {
  $w("#facultyDataset").onReady( () => {
  // how many characters to include in the shortened version
  const shortTextLength = 90;
  // set the fullText variable to be the text from the collection
  fullText = $w('#facultyDataset').getCurrentItem().bio;
  // if no text to display, collapse the text element and the button
  if (!fullText) {
    $w('#facultyBio').collapse();
    $w('#readMore').collapse();
  } else {
  // if the text has fewer or the same number of characters as shortTextLength characters, display it as is and collapse the "Show More" button
    if (fullText.length <= shortTextLength) {
      $w('#facultyBio').text = fullText;
      $w('#readMore').collapse();
    } else {
    // create the shortened version of the text and display it in the text element
      shortText = fullText.substr(0, shortTextLength) + "...";
      $w('#facultyBio').text = shortText;
    }
  }
});

});

export function readMore_click(event) {
// check the contents of the text element 
if ($w("#facultyBio").text === shortText) {
  // if currently displaying short text, display the full text
  $w("#facultyBio").text = fullText;
  $w("#readMore").label = "Show less";    
} else {
  // if currently displaying full text, display the short text
  $w("#facultyBio").text = shortText;
  $w("#readMore").label = "Show more";
}
}

Make sure that you are following the tutorial carefully and that all your code is correct.
https://support.wix.com/en/article/corvid-tutorial-creating-a-show-more-link#working-with-dynamic-text

let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text

$w.onReady(function () {
$w("#dynamicDataset").onReady(function () {
// how many characters to include in the shortened version
const shortTextLength = 40;
// set the fullText variable to be the text from the collection
fullText = $w('#dynamicDataset').getCurrentItem().textField;
// if no text to display, collapse the text element and the button
if (!fullText) {
$w('#myTextElement').collapse();
$w('#myButton').collapse();
} else {
// if the text has fewer or the same number of characters as shortTextLength characters, display it as is and collapse the "Show More" button
if (fullText.length <= shortTextLength) {
$w('#myTextElement').text = fullText;
$w('#myButton').collapse();
} else {
// create the shortened version of the text and display it in the text element
shortText = fullText.substr(0, shortTextLength) + "...";
$w('#myTextElement').text = shortText;
}
}
});

export function myButton_click(event) {
// check the contents of the text element 
if ($w("#myTextElement").text === shortText) {
// if currently displaying short text, display the full text
$w("#myTextElement").text = fullText;
$w("#myButton").label = "Show less"; 
} else {
// if currently displaying full text, display the short text
$w("#myTextElement").text = shortText;
$w("#myButton").label = "Show more";
}
}

Not helpful, but thank you. I have been through the code a few times and this doesn’t tell me anything new.

@rich51816

Okay so you not seen the five errors in your code then.

Anyways, this code from the tutorial only works for one show more/show less text element and button.

If you have multiple read more texts that you want to use on your page, then you need to add more short and full texts in the lets and add additional export functions for each text button and const statements for those text elements too.

Correct, I don’t know what the errors are or I would have fixed them and not submitted my question…Obviously. Why would I bother to hop on a forum and ask a question I already know the answer to?

From the documentation/tutorial:

“This works on regular pages and on dynamic item and category pages.”

I am trying to do this on a regular page using a repeater. So, I only have one Read More button and one Read More Text inside the repeater. Do you know if it’s possible to do this? Is my problem that I am using a repeater?