How do to make the simplest code for dynamic data?

Hello world!

I have a JSON file with more than 200 records.

I want that each record to be active button with unique actions.

The code is the following:

$.getJSON ("content.json",

{function (Data)}

for (var i = 0; i < 200; i ++) {}

var s = sym.getSymbol("base").createChildSymbol ("template", "CONT");

s.getSymbolElement ();

s.Element.attr ('id', 'symbol' + i);

s. $("imageholder") .css ({'background-image': "url ('" + data [i].) "}) (image_+_«_'_»)});

s. $("imageholder") .data ('myIndex', i);

s.$("imageHolder"). Data('title',Data[i].) (Name)

s.. Click$ ("imageholder") ("click", Function {}

If ($(this) .data ("myIndex") == 0) {}

WB = 10;

SYM.$("#symbol0"). Show();

SYM.$("#Symbol1"). Hide();

SYM.$("#Symbol2"). Hide();

SYM.$("#symbol3"). Hide();

sym.getComposition () .getStage ().getSymbol('placer').$("holder").css ({'background-image': "url (" + $(this).data('Large') + ")"});

sym.getComposition () .getStage ().getSymbol('placer').$("holdertxt").html ($(this) .data ('the kid'));

If (WB == 10) {}

sym.getSymbol("#symbol0").$("rect").animate ({opacity:1}, 700);

};

}

ElseIf ($(this) .data ("myIndex") == 1) {}

WB = 11;

SYM.$("#symbol0"). Hide();

SYM.$("#Symbol1"). Show();

sym.getComposition () .getStage ().getSymbol('placer').$("holder").css ({'background-image': "url (" + $(this).data('Large') + ")"});

sym.getComposition () .getStage ().getSymbol('placer').$("holdertxt").html ($(this) .data ('the kid'));

If (WB == 11) {}

sym.getSymbol("#symbol1").$("rect").animate ({opacity:1}, 700);

};

}

});

s. $("imageholder") .mouseout ("mouseout/mouseouthandler()", function (e) {}

If ($(this) .data ("myindex") == 0 & & WB! = 10) {}

sym.getSymbol("#symbol0").playReverse ("selectend");

}

ElseIf ($(this) .data ("myindex") == 1 & & WB! = 11) {}

sym.getSymbol("#symbol1").playReverse ("selectend");

}

}

});

s. $("imageholder") .mouseout ("mouseout/mouseouthandler()", function (e) {}

If ($(this) .data ("myindex") == 0 & & WB! = 10) {}

sym.getSymbol("#symbol0").play ("selectstart");

}

ElseIf ($(this) .data ("myindex") == 1 & & WB! = 11) {}

sym.getSymbol("#symbol1").play ("selectstart");

}

});

}

});

How is possible to place an each command or something else for not writing for each Index and for each function actions?

Now I'm writing for each function (passing of the mouse, click, mouseout/mouseouthandler()) the actions that each record in the JSON must do.

Can someone help me?

Based on your code above, I made the following assumptions:

  1. You have shown the code for two values of i (0 and 1) and want a similar code for the rest
  2. Two managers mouseout/mouseouthandler() in the code above is a typo, one of them is supposed to be a mouseover (according to the description at the bottom). In the solution, I will propose, I guess that one was supposed to be a manager of mouseover
  3. BM is a global variable and values range from 10, 11, 12... 10 + n - 1. Please check the code once though, I think that there is a logical problem with the closure, you create around WB in mouseout/mouseouthandler() handlers. I can't identify the intention if the proposed solution will be based on your code above.

Another bug in the code is in the way you join managers:

s.. Click$ ("imageholder") ("click", Function {}) must be changed to: s.$("imageholder"). on ("click", Function {})

and still other managers.

You can use the following to simplify your code:

$.getJSON("content.json", function (data) {
     for (var i = 0; i < data.length; i++) {
          var s = sym.getSymbol("base").createChildSymbol("template", "conts");
          var e = s.getSymbolElement(); 
          e.attr('id', 'symbol' + i); 
          s.$("imageholder").css({ "background-image": "url('" + data[i].image + "')" });
          s.$("imageholder").data('myIndex', i);
          s.$("imageholder").data('title', data[i].name); 

          s.$("imageholder").on("click", function (e) {
               WB = 10 + i;
               sym.$("#symbol0").show();
               sym.$("#symbol1").hide();
               sym.$("#symbol2").hide();
               sym.$("#symbol3").hide();
               sym.getComposition().getStage().getSymbol('placer').$("holder").css({ "background-image": " url(" + $(this).data('Large') + ")" });
               sym.getComposition().getStage().getSymbol('placer').$("holdertxt").html($(this).data('title'));
               sym.getSymbol("#symbol0").$("rect").animate({ opacity: 1 }, 700);
          });

          s.$("imageholder").on("mouseover", function (e) {
               //Looks like a logical bug, please double check.. I don't know how you are controlling WB from outside
                if(WB != 10 + i) {
                    sym.getSymbol("#symbol0").playReverse("selectend");
                }
         }); 

          s.$("imageholder").on("mouseout", function (e) {
               //Looks like a logical bug, please double check.. I don't know how you are controlling WB from outside
               if (WB != 10 + i) {
                    sym.getSymbol("#symbol0").play("selectstart");
               }
          });
     }
});

Another option would be to set up your event handlers in the symbol definition. The advantage is that all instances would automatically inherit the behavior. You just need to understand how to set the code. For example, in your case, you can attach the following click on Manager in the symbol itself imageholder element:

var i = sym.$("imageholder").data('myIndex');  //You will be setting the data on the instance while creating the instance. Rest of the code can use this as a param
WB = 10 + i; //Assuming WB to be available, change the logic accordingly
sym.$("#symbol0").show();
sym.$("#symbol1").hide();
sym.$("#symbol2").hide();
sym.$("#symbol3").hide();
sym.getComposition().getStage().getSymbol('placer').$("holder").css({ "background-image": " url(" + $(this).data('Large') + ")" });
sym.getComposition().getStage().getSymbol('placer').$("holdertxt").html($(this).data('title'));
sym.getSymbol("#symbol0").$("rect").animate({ opacity: 1 }, 700);

The code does not work as it is, but I hope it helps you move forward and you are able to achieve what you wanted. Let us know if you encounter other problems.

DIA-

Tags: Edge Animate

Similar Questions

Maybe you are looking for

  • Why only a Yahoo Group displays the column group name?

    I belong to several Yahoo groups and get individual emails from 3 of them. They all worked well until May 8, 2014, when the Freex news group began to display only "[email protected]" in the column. It's always like that. I can't be sure it's a Yah

  • Inactive links for quite awhile when opening pages

    Recently I faced a problem when all the page links are inactive for some time (from 10 to 20 sec) when opening/refreshing of web pages.Loading of the page its content, it can be the object of a scroll, flash works, but links can be used only with a c

  • page displayed incorrectly

    From time to time various web site displayed incorrectly - today, it's Facebook http://www.facebook.com/home.php?ref=hp but it another day it was my pages of the Bank.Generally, it corrects after the re - start the computer.Please advise how to stop

  • If the error code 43 makes you uninstall WLDD, replace with?

    Accoding to what I could find, WLDD is a driver of hardware compatibility. For example, if you delete it, you create compatibility issues... To avoid these problems, you have to replace it with something that will make your compatible hardware... Wha

  • Need help how to extract files from laptop which has a damaged keyboard

    I have an old laptop with a damaged keyboard that is running the same os as my new, Windows Vista and im trying to figure out how I can download files and media that I want to record as I am not keen to repair the old Toshiba satellite pro that the n