在一个应用程序中,我使用Ember和Ember Data的最新canary版本。我有以下路由器:
this.resource('articles', {path: '/articles'}, function() {
this.resource('article', {path: '/:article_id'});
});
在 ArticlesController 中,我指定了一些queryParams:
queryParams: ['category', 'search'],
category: '1', // defaults to 1
searchTerm: "",
在我的 ArticlesRoute 中,我指定了模型刷新和模型:
queryParams: {
category: {
refreshModel: true
}
},
model: function(params) {
// here I do use the params to return articles based on category and/or searchTerm
}
到目前为止,上述所有代码都非常完美。但是,当我在我的应用程序中执行this.transitionTo('article', articleObject)
或this.transitionToRoute('article', articleObject)
时,出现以下错误:
Error: You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route article
at Object.__exports__.default.subclass.createParamHandlerInfo (http://localhost:8000/vendor/ember/index.js:44242:21)
at Object.__exports__.default.subclass.applyToHandlers (http://localhost:8000/vendor/ember/index.js:44121:37)
at Object.__exports__.default.subclass.applyToState (http://localhost:8000/vendor/ember/index.js:44088:21)
at Object.Router.transitionByIntent (http://localhost:8000/vendor/ember/index.js:43312:33)
at Object.Router.refresh (http://localhost:8000/vendor/ember/index.js:43459:21)
at EmberObject.extend.refresh (http://localhost:8000/vendor/ember/index.js:22616:35)
at EmberObject.extend._actions.queryParamsDidChange (http://localhost:8000/vendor/ember/index.js:22328:22)
at Object.triggerEvent (http://localhost:8000/vendor/ember/index.js:24563:38)
at trigger (http://localhost:8000/vendor/ember/index.js:44812:16)
at fireQueryParamDidChange (http://localhost:8000/vendor/ember/index.js:43612:9) index.js:14220
Uncaught Error: Assertion Failed: Error: You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route article index.js:3658
这种奇怪的错误只发生在我第一次点击某个类别时,所以queryParam category
被更改,然后触发转换到文章。
我尝试使用debugger;
语句来获取错误的来源。但是,这似乎是一个调用此错误的事件。搜索源代码时,我发现错误来自ember.js的第44242行。
有没有人知道为什么在我转换到非 query-params-new路线后会发生此错误?
编辑:现在也在Github:https://github.com/emberjs/ember.js/issues/5070(评论Github) JSBin:http://emberjs.jsbin.com/yiquyupa
答案 0 :(得分:3)
我在afterModel
回调中遇到了几乎相同的问题,其中父路由/控制器有queryParams。
我发现如果你只是将来自过渡参数的queryParams(不是查询参数为null / undefined)传递给Route.transitionTo
/ Route.replaceWith
,那么过渡就完成了
示例:
afterModel: function(model, transition, queryParams) {
// FIXME: unresolved Ember issue https://github.com/emberjs/ember.js/issues/5070
this.replaceWith('another.route', model, { queryParams: transition.queryParams});
}
我不知道为什么会发生这种情况,但是queryParams仍然是一个相对较新的功能,但仍然有一些粗糙的边缘。