问题描述
我正在尝试以编程方式在Ember.Mixin中定义queryParams。
I'm trying to programmatically define queryParams in an Ember.Mixin.
mixin有一个方法,在初始化包含mixin的控制器时会调用该方法。
The mixin has a method which is called when the controller holding the mixin is initialized.
setupQueryParams: (params) ->
params.forEach (param) =>
@get('queryParams').push(param)
稍后在定义的操作中在mixin上,我调用 @transitionToRoute({queryParams:{someParam:'something'}})
没有任何反应。但是,当我显式定义自己的queryParams时,此方法有效。
Later in an action defined on the mixin I call @transitionToRoute({queryParams: {someParam: 'something'}})
nothing happens. However when I explicitly define my queryParams, this works.
推荐答案
queryParams
是从类的原型而不是实例的原型上解决的,因此不会及时应用任何 init
功能来让ember对其进行解析。
queryParams
are resolved off the proto of the class, not an instance, so any init
functionality wouldn't be applied in time for ember to resolve it.
这仅意味着 queryParams
的后期绑定无法以您想要的方式进行。
This just means late binding of the queryParams
isn't possible in the way you want.
这篇关于灰烬:在Mixin中以编程方式设置queryParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!