Ember: binding controller properties to query parameters

♀尐吖头ヾ 提交于 2019-12-25 08:37:08

问题


I know ember is supposed to have some built-in binding of controller properties and query params. Docs state (referring to a previous example):

once the articles route has been entered, any changes 
to the category query param in the URL will update the 
category property on controller:articles, and vice versa.

I take "vice versa" to mean that if there's a change to one of the controller properties, it would also be reflected in the QPs on the URL. perhaps I am mis-interpreting that. But if my interpretation is correct (it's probably not), it's not what's actually happening.

I put together a twiddle to demonstrate

Is there a way to bind the QPs on the url to the controller properties so that

a) the controller properties update if the url QPs update

b) the QPs in the location bar update if the controller properties update

?

Any help appreciated


回答1:


In deleteStuff, you can just set it to default value then it will take care of refreshing route and it will not be shown in URL if its default value. So to make it work include queryParams: { q:{ refreshModel: true }} in routes/search.js file.

Refer this twiddle it will update params q and it will be updated in URL and it will refresh route. and if q is set to default value then it will not be shown in URL.



来源:https://stackoverflow.com/questions/42128204/ember-binding-controller-properties-to-query-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!