problem $w() is not a function

hello every body and sorry for my bad english

does somebody knows why this code does not work?: i have the message $w() is not a function

for ( var i = 0 ; i < $w( “#dynamicDataset” ).getCurrentItem().equipements.length; i++) {

$w("#cat"+i).show();
//let x=“#cat”+1
//$w(“#cat”+x).show()

//let rech=$w(“#dynamicDataset”).getCurrentItem().equipements[i]
//wixData.query(“equipements”)
//.contains(“title”,rech)
//.then((result2)=>{

// $w(“#act” + i+1).src=result2.items.icon
//});
}

Is your page setup like this here.

With the error being shown in the developer console window in the preview mode?
TypeError: $w(…).getCurrentItem is not a function

This usually means that you can’t use it like that, so you have to look at a different way of writing your code.

Which in your case, it is the second command of your for loop which is the condition that is not correct. The loop will only run whilst this condition is true.

I think for starters that you can’t use a dataset like that in a for loop.
https://www.w3schools.com/js/js_loop_for.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for
https://stackoverflow.com/questions/9266739/javascript-for-var-i-0-browser-incompatibilities

This has also been talked about in similar posts here.
https://www.wix.com/corvid/forum/community-discussion/all-row-delete-in-collections
https://www.wix.com/corvid/forum/community-discussion/all-row-delete-in-collections-1

Where they both use the for loop in code as this.

 for (var i = 0; i < result.items.length; i++){

Also, check the second link from above, as Yisreal has mentioned in that forum post about using it like this below, which might be of benefit to you.

let dataset = $w("#dynamicDataset");

Thanks for this answer but the loop is correct and works. This is this code: $w(" [#cat](https://www.wix.com/corvid/forum/search/~num~cat) "+i).show(); who’s not work . I think it is because i is not a string. how to convert i to string ?

The variable i is converted to a string when it is concatened to a string.

$w('#cat'+i).show()

This will work if #cat1 is an element on the screen. If the element is #cat01, then you will have to pad with 0.

Also, I see that the for loop is outside the onReady() function. The $w context selector is not accessible outside of the onReady() or other event handlers (e.g. onClick, onChange, etc).

@yisrael-wix Hello brewmaster
My code is in onReady()
And this code give me the same error message

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

ok, it is page “Entreprises Francophones Detail”
problem line 40

https://editor.wix.com/html/editor/web/renderer/edit/fa9ca072-2b07-4274-8cf8-810116b786cc?metaSiteId=54ba3451-ea8f-467c-a640-67e0b290e628&editorSessionId=c6abea8d-a58b-426c-bf51-6cbc9f096252&referralInfo=dashboard

thanks a lot

The line you have is incorrect.

$w(`#cat+i`).show();

The backticks, turn everything inside of them into a string. Therefore, what you end up with is an element Id of ‘#cat+1’.

What you want is:

$w('#cat'+i).show();

What this does is takes the string ‘#cat’ and then appends (as a string) the number contained in i.

You can also do this:

$w(`#cat${i}`).show();

For more information on template literals (strings inside of back ticks), see this article.

@yisrael-wix Sorry but i just test the 2 codes and i have exactly the same error message…i don t

@fredericmassard Where are the #cat screen elements? I can’t find them.

Plus, when I load the page, I don’t get the error. I don’t think that code runs at all when I load the page. How do you load the page?

Are you trying to reference #cat1 or #act1?

Elements are act1 act2 act3…

elements are here

I load directly from wix

So you want this:

$w(`#act${i}`).show();

Please realize that your page is quite complex, having many components. We are unable to debug or rewrite extremely complex code/pages. Please try to isolate the problem to a minimal scenario so that we can properly evaluate your problem.

Ok