I’m trying to create an html string and save it into a collection to display on a dynamic page.
I have:
text =
wixData . get ( “CourseList” , listItems [ x ]. _id )
. then (( item ) => {
item . train = t ext ; // train is a rich text field in the collection
wixData . update ( “CourseList” , item );
})
. catch (( err ) => {
console . log ( err );
});
But the field in the collection has an error because it doesn’t convert the string to rich text. I might be going about this all wrong… any help would be appreciated.
Alternatively, I could save the html as a string in the collection, but then how do I display as html in a repeater? I’ve tried the following, but it doesn’t work.
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
$w ( "#courseRepeater" ). onItemReady (( $item , itemData , index ) => {
$item ( "#courseImage" ). src = itemData . image ;
$item ( "#courseImage" ). alt = itemData . imageAltText ;
$item ( "#titleText" ). text = itemData . title ;
$item ( "#summaryText" ). html = itemData . shortDescription ;
**$item** **(** **"#timesText"** **).** **html** **=** **itemData** **.** **train** **; // train is a text field with html formatting**
});
wixData . query ( "CourseList" )
. contains ( "category" , "k12" )
. ascending ( "title" )
. find ()
. then (( results ) => {
**if** ( results . totalCount > 0 ) {
$w ( "#courseRepeater" ). data = results . items ;
}
})
. **catch** (( error ) => {
console . log ( "Error:" , error . message );
});
})