简体   繁体   中英

Ember: binding query parameter arrays to controller properties

I get how to bind query parameters to controller properties and that's working great. But my problem now is, how to bind query parameters that are arrays to controller properties (that are arrays)?

Either I am not doing something right (quite likely) or this is not supported in ember.

I made a twiddle to demonstrate.

(Note, when the twiddle loads the url is /search . You have to manually change it to: /search?foo[]=1&foo[]=2&foo[]=3 - sorry)

When the twiddle page loads, the QPs:

foo[]=1&foo[]=2&foo[]=3

are correctly bound to a controller property that is an array:

foo: ['1','2','3']

But when the foo array is manipulated via the action (delete #2), ember changes the format of the array expressed as QPs to &foo=1%2C3 aka foo=1,3

Which in turn changes the format of the foo controller property from

foo: ['1','3']

to

foo: '1,3'

Is it possible for ember to retain the parameter-array format when a QP is bound to an array?

Took me a while to dig up, but it appears somewhere along the way ember changed the QP format for arrays to json. But that's sort of a work-in-progress. Short discussion here .

I was able to get a twiddle working with a QP array bound to controller property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM