App = Ember.Application.create();
App.Router.map(function() {
this.route("cases");
});
App.IndexController = Ember.Controller.extend({
actions: {
login: function() {
transitionToRoute('cases','data1','data2');//send data to case
}
}
});
App.CasesRoute = Ember.Route.extend({
model: function(xxx1,xxx2) {
//get 'data'
alert(xxx1);
}
});
我想从IndexController发送一些数据到CaseRoute中的模型,我是初学者并阅读this但我不明白。 这种方式对模型发送值是否正确?
答案 0 :(得分:1)
这是将参数传递给路由的正确方法(替代方式:查询参数)。您的代码需要一些更正:
App = Ember.Application.create();
App.Router.map(function() {
this.route("cases", { path: '/cases/:data1/:data2' });
});
App.IndexController = Ember.Controller.extend({
actions: {
login: function() {
this.transitionToRoute('cases','data1','data2');
}
}
});
App.CasesRoute = Ember.Route.extend({
model: function(params) {
//use params.data1 to get 'data1'
console.log("data1", params.data1);
console.log("data2", params.data2);
}
});