简体   繁体   English

两个请求在同一条路线上emberjs 2

[英]Two request at same route emberjs 2

This is my scenario. 这是我的情况。

  1. User input a zipcode and name location 用户输入邮政编码和名称位置
  2. Load data from a API which a payload that contains a location list 从API加载数据,该API的有效负载包含位置列表
  3. Show the location list for the user pick the right one. 显示位置列表,为用户选择合适的位置。
  4. Then bind data to complete registration and submit registration 然后绑定数据以完成注册并提交注册

First I tried a modal as component. 首先,我尝试使用模式作为组件。 After I see this is incorrect, then I moved to ember-data and do this on the route. 看到这是不正确的,然后我移至ember-data并在路线上执行此操作。 I create a ember-data for location list (which be a component) and other for register values. 我为位置列表(属于组件)创建了余烬数据,为寄存器值创建了余烬数据。 I create the adapter and a serializer. 我创建了适配器和序列化器。 So I completely lost what do next. 所以我完全失去了下一步的工作。 How I do this, using a ember-data to search places(a GET) and a registration(POST) on the API? 如何使用余烬数据在API上搜索地点(GET)和注册(POST)?

if you have to make multiple requests at the same time you do 如果您必须同时提出多个要求,

Ember.RSVP.all([
  $.ajax(...),
  this.store.findAll('person'),
  ...
]).then(function([result1, result2, result3 ]){
 console.log('all requests finished');
})

if you want sequential request (one after another) you simply chain them 如果要顺序请求(一个接一个),只需将它们链接

$.ajax(...).then((ajaxResult) => { 
 return this.store.findAll('person')
}).then((person)=>{
 ....
}).then(function(){
 console.log('all requests finished')
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM