4

是否有可能在 pre2 中获取查询字符串参数?

例如,我们想转换到这样的路线:#/customer/CN-001whereCN-001将匹配一些沿/customer/:customernumber.

4

1 回答 1

0

我认为这就是你想要的:

路由器:

App = Ember.Application.create({
    ApplicationController: Ember.ObjectController.extend(),
    CustomerController: Ember.ObjectController.extend(),
    Router: Ember.Router.extend({
        root: Ember.Route.extend({                        
            index: Em.Route.extend({    
                route: '/',
                connectOutlets: function(router) {
                    router.route('/customer/CN-001');
                }
            }),
            customer: Em.Route.extend({            
                route: '/customer/:customernumber',
                connectOutlets: function(router, customer) {                    
                    router.get("applicationController").connectOutlet('customer', customer);                    
                },
                serialize:  function(router, context){
                    return { id: context.number };
                },
                deserialize: function(router, params) {
                    return Ember.Object.create({ number: params.customernumber });
                }
            })            
        })
    })
});

App.CustomerView = Ember.View.extend({
    templateName: 'customer'
})

模板:

<script type="text/x-handlebars" data-template-name="application">    
    {{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="customer">
  <h2>Customer</h2>  
    {{number}}
</script>

是一个显示此工作的jsfiddle。我希望它有所帮助。

于 2013-08-08T00:10:15.927 回答