javascript - Promise based property Ember - Stack Overflow

I've got a controller that has a searchQuery and suggestions property. The suggestions e from an A

I've got a controller that has a searchQuery and suggestions property. The suggestions e from an AJAX request. How can I make the suggestions property a promise in my Controller?

app/controllers/application.js

import Ember from 'ember';

const { puted, $ } = Ember;

export default Ember.Controller.extend({
  searchQuery: '',
  suggestions: puted('searchQuery', function() {
    return $.getJSON(`songs/search.json?q=${this.get('searchQuery')}`);
  })
});

I've got a controller that has a searchQuery and suggestions property. The suggestions e from an AJAX request. How can I make the suggestions property a promise in my Controller?

app/controllers/application.js

import Ember from 'ember';

const { puted, $ } = Ember;

export default Ember.Controller.extend({
  searchQuery: '',
  suggestions: puted('searchQuery', function() {
    return $.getJSON(`songs/search.json?q=${this.get('searchQuery')}`);
  })
});
Share Improve this question edited Aug 16, 2015 at 20:23 Jon Koops asked Nov 15, 2013 at 19:58 Jon KoopsJon Koops 9,3016 gold badges32 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I assume you mean, how can I get the results from the promise, since you are returning a promise to the suggestions property.

searchQuery: '',

suggestions: [],

suggestionsUpdater: Ember.observer('searchQuery', function(){
  var self = this;
  Ember.$.getJSON('songs/search.json?q=' + this.get('searchQuery')).then(function(data){
    self.set('suggestions', data);
  });
})

There are only a few places where you can return/send a promise and ember's going to assume you didn't want to store the promise. The model hook, and transitionTo/transitionToRoute methods. The rest of the time they leave it up to you, in case you actually wanted to keep track of the promise.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742367303a4430570.html

相关推荐

  • javascript - Promise based property Ember - Stack Overflow

    I've got a controller that has a searchQuery and suggestions property. The suggestions e from an A

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信