Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set property of nested array by index dynamically #127

Open
daveed80 opened this issue Oct 31, 2014 · 3 comments
Open

Cannot set property of nested array by index dynamically #127

daveed80 opened this issue Oct 31, 2014 · 3 comments

Comments

@daveed80
Copy link

I'm attempting to set a property of a nested array dynamically but am unable to do so.

Model :

{"Alias":"sample","Id":0,
Traits: [
{"AttrValue":null},
{"AttrValue":null}
]
}

This of course works fine:

// this.model.set({ 'Traits[0].AttrValue': 'test' });

This does not:

// var i = 2;
// var prop = 'Traits[' + i + '].AttrValue';
// this.model.set({' prop ' : 'test'});

I'm sure I just can't see the sailboat at the moment (exhaustion) so any help would be greatly appreciated.

Thanks in advance!

@afeld
Copy link
Owner

afeld commented Oct 31, 2014

Figure it out?

@daveed80
Copy link
Author

Thanks so much for the reply!

Well, both yes and no...

I just realized I can do:

// var traits = this.model.get('Traits');
// traits[0].AttrValue = 'test';
// this.model.set('Traits', traits);

What I would inevitably like to do is find the 'trait' object from the array by 'AttrName', and set it directly, avoiding needing to know the index and still updating the top level model.

Any suggestions?

@daveed80 daveed80 reopened this Oct 31, 2014
@daveed80
Copy link
Author

By the way, excellent work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants