• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Propriété .visible avec une variable

Community Beginner ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Bonjour,
Je souhaite, à partir d'un menu déroulant, rendre visible certains éléments (clips).
J'ai pour cela écrit ce bout de code

 

if(!this.menu_hom_change_cbk) {
	function menu_hom_change(evt) {
		// Début de votre code personnalisé
		console.log(evt.target.value);
		var choix_h = ((evt.target.value)+"_mc");
		//alert (choix_h);
		this.choix_h.visible = true;
	}
	$("#dom_overlay_container").on("change", "#menu_hom", menu_hom_change.bind(this));
	this.menu_hom_change_cbk = true;
}

 

qui récupère l'option de menu cliquée dans une variable, puis je réutilise cette variable pour afficher l'objet sélectionné comme ceci : this. ma_variable.visible = true
Mais cela ne fonctionne pas : le nom du clip obtenu avec la variable est correct (vérifié avec la fonction "alert").
Je pense que la syntaxe est incorrect dans la ligne de la propriété .visible et je ne sais pas comment il faut l'écrire.
Merci de votre aide.

***

Hello, I want, from a drop-down menu, to make certain elements (clips) visible. For that I wrote this piece of code which gets the menu option clicked in a variable, then I reuse that variable to display the selected object like this: this. my_variable.visible = true But that does not work: the name of the clip obtained with the variable is correct (checked with the "alert" function). I think the syntax is incorrect in the line for the .visible property and I don't know how to write it. Thank you for your help.

Views

90

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

your code is assigning a string's visible proptery to true and strings don't have visible properties.

 

you need to first convert that string to an object and then assign the object's visible property:  to coerce a string to an object use array notation:

 

 

 

var choix_h = ((evt.target.value)+"_mc");
		//alert (choix_h);
		this[choix_h].visible = true

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

It works.
Thank you very much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines