Ember查询参数不会在请求中发送参数 [英] Ember query params not sending params in the request

查看:262
本文介绍了Ember查询参数不会在请求中发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将query-params-new标志设置为 true



使用最新的ember和ember数据。 Ember:1.6.0-beta.1 + canary.b5b90241 ember.js和Ember Data:1.0.0-beta.7 + canary.b45e23ba



应用程序适配器已设置到:

 导出默认DS.RESTAdapter.extend({
host:'http://example.com ',
命名空间:'api / v2',
标头:{
ClientId:a-key,
Access-Control-Allow-Origin *,
访问控制允许标题:X请求与
}
});

位置路线如下所示:

 导出默认值Ember.Route.extend({
model:function(params){
return this.store.find('restaurant');
}
});

位置控制器看起来像这样

 导出默认值Ember.ArrayController.extend({

queryParams:['lat','lon','limit'],

lat:null,
lon:null,
limit:null,

});

导航到此网址 http://example.com/locations?lat = 47.620508& limit = 22& lon = -122.349174 Ember数据发送 http://example.com/locations 作为请求。 p>

我必须缺少某些东西?

解决方案

需要做的是获取查询参数 - 新的工作正常。



首先,你说你使用最新的ember,但不要指定是否是最新的稳定释放或最新的金丝雀释放(主)。为了使用query-params-new,你需要使用加那利,这只是主分支。它在稳定版或测试版中尚不可用,但您可以在此下载



其次,您需要在控制器中指定要绑定到路由的参数。您的位置控制器需要看起来像这样:

 导出默认值Ember.ArrayController.extend({
queryParams: ['lat','lon','limit']
});

所有这些都在Ember网站上记录。 http://emberjs.com/guides/routing/query-params/



根据其他问题信息编辑



看起来您没有使用你的路线中的params。您可以使用 findQuery 将参数发送到服务器,如下所示:

 导出默认值Ember.Route.extend({
model:function(params){
return this.store.findQuery('restaurant',params);
}
}) ;


The query-params-new flag set to true.

Using latest ember and ember data. Ember: 1.6.0-beta.1+canary.b5b90241 ember.js and Ember Data : 1.0.0-beta.7+canary.b45e23ba

Application Adapter is set to this:

export default DS.RESTAdapter.extend({
  host: 'http://example.com',
  namespace: 'api/v2',
  headers: {
    "ClientId": "a-key",
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "X-Requested-With"
  }
});

The locations route looks like this:

export default Ember.Route.extend({
  model: function(params){
    return this.store.find('restaurant');
  }
});

The locations controller looks like this

export default Ember.ArrayController.extend({

  queryParams: ['lat', 'lon', 'limit'],

  lat: null,
  lon: null,
  limit: null,

});

Navigating to this url http://example.com/locations?lat=47.620508&limit=22&lon=-122.349174 Ember data sends http://example.com/locations as the request.

I must be missing something?

解决方案

There are a few things you need to do to get query-params-new working as expected.

First, you say you're using the latest ember, but don't specify whether it's the latest stable release or the latest canary release (master). In order to use query-params-new, you need to use canary, which is just the master branch. It is not available in the stable or beta releases yet, but you can download it here.

Second, you need to specify in your controller which params you want to bind to the route. Your locations controller would need to look something like this:

export default Ember.ArrayController.extend({
  queryParams: ['lat', 'lon', 'limit']
});

All of this is documented on the Ember site. http://emberjs.com/guides/routing/query-params/

Edit based on additional question info:

It looks like you're not using the params in your route. You can use findQuery to send the params to the server like so:

export default Ember.Route.extend({
  model: function(params){
    return this.store.findQuery('restaurant', params);
  }
});

这篇关于Ember查询参数不会在请求中发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆