0

I am trying to add attributes to a model, on the fly, like this:

var fieldName = e.currentTarget.name;
var model = this.collection.images.get("2");
model.set({fieldName: e.currentTarget.value});

So, as a user types in a given textbox, this code will be called. The field name is a data attribute for a textbox that corresponds to the model attribute name. The problem is that when this code runs, instead of inserting the given data into the correct attribute, it creates a new one called "fieldName". For example, if e.currentTarget.Name = "test", I would expect that the model attribute called "test" would be set to a given value, not the literal "fieldName". Is there anyway to use the passed value and not the literal?

1 Answer 1

2

Try this syntax instead:

model.set(fieldName, e.currentTarget.value);

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

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.