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

Custom toJSON method causes problems binding a Backbone collection in selectOptions #279

Open
will-r opened this issue Mar 26, 2015 · 4 comments

Comments

@will-r
Copy link

will-r commented Mar 26, 2015

The binding of selectOptions to a backbone collection involves a call to collection.toJSON. If that function is special, the returned results will not match the expected format. In our case we were wrapping the model JSON in a root element to support old rails conventions.

We found two reasonable fixes: anticipate this JSON structure in the labelPath and valuePath, or remove the custom JSON wrapper and let things happen normally.

I am left with the feeling that Stickit is not very comfortable with backbone objects as bound values rather than bindee. It would feel more robust if evaluatePath was able to do the right thing when obj is a model, so that models could be passed through without serialization. Would you consider a pull request along those lines?

@akre54
Copy link
Contributor

akre54 commented Mar 26, 2015

Sure, I'd love to see what a PR for this looks like. We want to support the common case first and foremost, but not trap ourselves into a situation where we're running into issues with totally reasonable use cases (like yours).

@abzainuddin
Copy link

I have a similar issue, where toJSON is custom. Perhaps making an option to choose which function to call to serialize the Collection, and defaulting to toJSON?

selectOptions: {
    collection: foo,
    serializer: 'bar'
}

Will make PR if given a go.

@abzainuddin
Copy link

Bump. Go or no go?

@akre54
Copy link
Contributor

akre54 commented Mar 29, 2017

Sure. Would love to see what a fix for this looks like.

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

3 participants