0

I have a jQuery object that contains strings. I use it in many places with no problems.

The object (for example):

resources {
    res1: "Resource 1",
    res2: "Resource 2",
    ... etc ...
}

I use this object like this:

ctl.text(resources.res1);

This works fine, but now I need to use these string resources like:

options {
    resources.res1: "Some string",
    resources.res2: "Another string"
}

In the above code I get an error starting at .res1 stating that a : is expected. Since resources.res1 contains a string I thought this should be valid. How can I use resources.res1 when creating options {}?

1
  • Can you post your actual code and the error message? Maybe at jsfiddle.net? (Preferably, don't make it executable on here if there are errors) Commented Nov 14, 2014 at 0:12

3 Answers 3

1

You're doing it the wrong way around, if you're trying to set options values from resources you need:

options {
    val1: resources.res1,
    val2: resources.res2
}
Sign up to request clarification or add additional context in comments.

1 Comment

you are right. The way I had it before was working because I used an actual string. I have to reverse the key/value logic on the routine I'm calling, but that will fix it. Thank you!
1

you need to create options object first, then push in the values, as:

var options = {};
options[resources['res1']] = "Some String";
options[resources['res2']] = "Aonther String";
console.log(options);
//gives
// Object { Resource 1="Some String", Resource 2="Aonther String"}

Comments

0

Why not do

options = {
    resources : {
        res1: "Some string",
        res2: "Another string"
    }
}

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.