sorry for this simple question but I’m getting crazy. I’m stuck into this code:
simple “pizzaDB”.
when I ran code, table is filled with all pizza elements.
try to assign first image queried to image item, I get error:
Wix code SDK Warning: The src parameter of “image1” that is passed to the src method cannot be set to null or undefined.
pizzapic item does not have “.src” property to work with…
can someone help me to understand how to retrieve image from collection and assign to item with corvid code? Thanks in advance for your time an help.
further details below:
below simple backed code with query function
export function pizzaMenu() {
return wixData.query( ‘pizzaListDB’ )
.find()
.then ((results) => {
return results
})
}
front end code:
$w.onReady( function () {
pizzaMenu()
.then((menu) => {
$w( ‘#menu’ ).rows=menu.items
$w( ‘#menu’ ).show
let cache=menu.items
//below code that gives error
$w( ‘#image1’ ).src=cache[ 0 ].pizzaPic.src
})
front end interface:
$w('#image1').src=cache[0].pizzaPic.src
delete —> .src at the end
$w('#image1').src=cache[0].pizzaPic
console.log(cache[0].pizzaPic)
and try again. Also take a look into CONSOLE and see the result.
In CONSOLE you should see something like…
wix:image://v1/b03143_34f0e652a2e04aa9a7cae24d4c618137~mv2.png/Vladimir%20putin.png#originWidth=256&originHeight=256"
Thank you.
but I cannot assign an object to single item. below you will find
- output for console.log(cache[0].pizzaPic)
- error I get after $w( ’ #image1 ’ ).src=cache[ 0 ].pizzaPic
@fblandino
Try…
console.log(console.log(cache[0].pizzaPic.uri)
$w('#image1').src=cache[0].pizzaPic.uri
When i compare your DB-results with mine, then i can recognize some differences belonging to the IMAGE and its SOURCE-path.
So when you take this example one…
https://www.media-junkie.com/pflegeservice
…where i have also a DATABASE containing some IMAGES in it.
When Searching for a LAST-NAME in the DB, like for example —> “Putin” and after clicking on SEARCH, you will see some results in the CONSOLE.
So if you compare now my IMAGE-path with your one, you will recognize a difference.
wix:image://v1/b03143_34f0e652a2e04aa9a7cae24d4c618137~mv2.png/Vladimir%20putin.png#originWidth=256&originHeight=256"
I do not know why your IMAGE-path-structure differs from mine, although in my DB the PIC-FIELD also it setted to —> IMAGE.
compare with DATABASE of my given example.
Perhaps you upload your pics by using the upload-process and not manualy inputing them into your DB, like i did it.
@russian-dima : Thank you for your time.
spent 2 days and finally discovered my (silly) mistake. As you said, I uploaded pics manually. Doing by code makes everything work.
thank you for your time!
@fblandino You are welcome ![:wink: :wink:](/images/emoji/google_classic/wink.png?v=12)