0

I wrote a function which take an id of the link as a name of JSON dataset.

$('.link').click(function() {
    var dataset = $(this).attr("id");
    for (var i = 0; i < chart.series.length; i++) {
        chart.series[i].setData(lata.dataset[i].data);
    }
});

But in this case dataset is string and it doesn't works. So how to get object from JSON file by string?

1
  • 1
    how big is this JSON data set that you are storing in the id? Commented Sep 6, 2012 at 11:52

2 Answers 2

1

Use the [] operator:

chart.series[i].setData(lata[dataset][i].data);

foo['bar'] and foo.bar are equivalent - except the fact that [] takes an expression and thus allows you to use e.g. a variable.

Sign up to request clarification or add additional context in comments.

Comments

0
chart.series[i].setData(lata[dataset][i].data);

this would be valid even if dataset is nto a valid identifier like "a b"

Comments

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.