0

I have an object array for customization of colors on my website. It gets generated like this when the colors are selected by the user:

colours = {
  "a":["red", "green", "blue"],
  "b":["pink", "yellow", "red"],
  "c":["violet", "black"],
  //and lots more
}

What I am trying to achieve is to connect (this will vary) the value of a with d and c with x. What ever the change is done in the values of a should be the values of d. I have multiple pages like this where I have to connect different values. How can I do this is it possible? It would be nice if I could set it on the header of every page like this a=d or colours[a] = colours[d].

6
  • 2
    Consider a js framework like Knockout: knockoutjs.com "dependency tracking" and "declarative bindings" Commented Aug 1, 2012 at 21:42
  • What do you mean by "a change is done" - do they start with different values or are they always the same? Commented Aug 1, 2012 at 21:56
  • @Bergi It starts out as an empty object colours = {} Commented Aug 1, 2012 at 22:02
  • @MattBall Thanks, i did not notice it. Commented Aug 1, 2012 at 22:03
  • So when do you need to connect the "a" array with the "d" array? Are thy added anytime later; do you know the connections before? Commented Aug 1, 2012 at 22:04

1 Answer 1

0

Ok i found a way, I am not sure if this is the right approach for it. On my main html page header I made another object like this:

 connections = {'a':'d', 'c':'x'};
 // the key to be connected : the key to connect to

Then in my coding page:

 for (ax in connections) {
 // this will create a loop through connections object
    var ay = connections[ax];
    colours[ay] = colours[ax];
 // this will make a and d, c and x equal in colours.

That solved the problem. Thank you all for helping and I wish this will be helpful for some one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.