Dynamic keys #54

Closed
kwizzn opened this Issue Jan 18, 2013 · 2 comments

2 participants

@kwizzn

This obviously won't work:

var dynamicDeepKey = 'foo';
model.set({ 'prefix.' + dynamicDeepKey: true });

All I can think of to solve this are hacky solutions like using "prefix.$dynamicDeepKey" as a key and replacing all keys beginning with "$" with something that needs to be provided e.g. in the options map, like so:

model.set({ 'prefix.$dynamicDeepKey': true }, { keys: {
    dynamicDeepKey: 'foo'
} });

Can anyone think of a better idea?

@mgevans

It's slightly more verbose, but how about using []?

var dynamicDeepKey = 'foo',
    objectToSet = {};
objectToSet['prefix.' + dynamicDeepKey] = true;
model.set(objectToSet);
@kwizzn

Straightforward, you're right, @mgevans. I was just wondering if the plugin addresses that issue as well as it does with the array index notation:

model.get('myArray.0.someKey')

@kwizzn kwizzn closed this Jan 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment