灰烬力量选择问题

时间:2018-09-11 02:20:22

标签: ember.js ember-power-select

我在使用Ember Power Select时遇到一些问题。我可以单独在模板上正确处理数据,但是由于某些原因,电源选择无法让我从下面的组件代码中的fetch调用中获取任何数据...

components / flight-search.js

import Component from '@ember/component';

export default Component.extend({
  flightResults: null,
  airResults: null,
  actions: {
    searchIATA(term) {
      let query = `https://iatacodes.org/api/v6/autocomplete?api_key=e7c1b7cf-62fb-440c-a0ef-4facebe1ab86&query=${term}`;
      return fetch(query).then(function(response) {
        return response.json();
      }).then(results => {
        this.set('airResults', results);
      });
    },
  }
});

components / flight-search.hbs

{{#each airResults.response.airports as |airport|}}
  {{airport.name}} - {{airport.code}}
{{/each}}

{{#power-select-typeahead
  search=(action "searchIATA")
  triggerClass="bootstrap-theme-trigger"
  dropdownClass="slide-fade bootstrap-theme-dropdown"
  selected=selectedType
  loadingMessage="Searching..."
  placeholder="e.g. New York, NY"
  onchange=(action (mut selectedType))
  as |result|
}}
<div class="-detail">
  {{result.response.airports.name}}
</div>
{{/power-select-typeahead}}

在电源选择上方和外部的通知我已经说明,可以根据需要获取数据。

非常感谢,谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试一下,我在两个地方都包含了箭头功能。

searchIATA(term) {
    let query = `https://iatacodes.org/api/v6/autocomplete?api_key=e7c1b7cf-62fb-440c-a0ef-4facebe1ab86&query=${term}`;
    return fetch(query).then(response => response.json()).then(results => {
        this.set('airResults', results);
    });
}