我是新來的燼,我試圖用transitionTo與queryParams,但我無法讓它工作我試了很多解決方案,但我找不到什麼是我的代碼錯了。這裏的兩條路線我轉型之間的代碼:Ember TransitionTo與queryParams不起作用
1 index.js:
export default Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
controller.set("model", model);
},
model() {
return {
searchQuery: ""
};
},
actions: {
search() {
const query = this.controller.get("model.searchQuery");
this.transitionTo("/search-results", {
quaryParams: {
q: query
}
});
}
}
});
2搜索results.js:
export default Ember.Route.extend({
model() {
return {
fieldsInput: []
};
},
setupController: function(controller, model) {
this._super(controller, model);
controller.set("model", model);
}
});
我不知道是否應該添加任何其他內容。我試圖設置控制器上的queryParams,但它也沒有工作。此外,我嘗試添加
queryParams: {
q: ""
},
到搜索結果路由但沒有用。
謝謝你的回覆。但我試過這個,但它也沒有工作。它只是去沒有查詢參數的路線 – moamenezzat
可能有很多不工作的原因。但我在答覆中提到了一個關鍵部分。這是真的,它會起作用。看看這個[twiddle](https://ember-twiddle.com/4b358521437ddbf62be17af55e7b27ce?openFiles=routes.application.js%2C&route=%2Fsearch-results%3Fq%3DchangedValue)。如果你準備不工作旋轉,那麼將很容易解決 – kumkanillam
謝謝你:)。旋律給了我失蹤的一塊。它正在添加路由上的queryParms對象。請添加更新您的答案,將其標記爲正確的答案。 – moamenezzat