1
页面上有选择国家的选项,需要将选定的值保存在URL中。 我在路由驱动控制器中声明了查询参数。 这都是工作!如果国家/地区选择更改,则URL也会更改。Ember.js:刷新页面时选择状态未保存在URL中
演示:http://output.jsbin.com/releza
但是,如果我重新载入页面与一些有效的GET PARAMS那么PARAMS转换为“未定义”。 例如,我尝试加载页面
http://output.jsbin.com/releza#/?country=2
,重定向到
http://output.jsbin.com/releza#/?country=undefined
为什么?
# index.hbl
<script type="text/x-handlebars" id="index">
{{view "select" content=countries
optionValuePath="content.id"
optionLabelPath="content.name"
value=country
prompt="Select a country"}}
</script>
# apps.js
App = Ember.Application.create({});
// ROUTES
App.IndexRoute = Ember.Route.extend({
setupController: function(controller, model) {
controller.set('countries', this.store.find('country'));
}
});
// CONTROLLERS
App.IndexController = Ember.Controller.extend({
queryParams: ['country'],
country: null,
});
// MODELS
App.Country = DS.Model.extend({
name: DS.attr('string'),
});
$.mockjax({
url: "/countries",
dataType: 'json',
responseText: {
"country": [
{"id":1, "name":"Абхазия"},
{"id":2, "name":"Австралия"},
{"id":3, "name":"Австрия"},
{"id":4,"name":"Азейбарджан"},
],
}
});
哦,对! 谢谢! –
如果我需要两个模型(和两个相应的选择)会怎么样。例如,国家和城市。在这种情况下,我怎样才能代表城市? –
http://jsbin.com/citomu/2/edit?html,js输出 –