从计算内部返回一个值,使得AJAX调用在Ember中不起作用

时间:2018-06-08 06:49:40

标签: javascript ember.js promise handlebars.js

我使用Ember作为我的webapp,我有这段代码:

 {{#if canAcceptPayPal}}

}),

但这只返回一个promise而不是boolean值。我在车把中使用它:

canAcceptPayPal: computed('data.event.paymentCurrency', function() {
this.get('store').queryRecord('setting', {})
  .then(setting => {
    this.set('canAcceptPayPal', (setting.paypalSandboxUsername || setting.paypalLiveUsername) && find(paymentCurrencies, ['code', this.get('data.event.paymentCurrency')]).paypal);
    this.rerender();
  });

我在这里缺少什么?

解决方案
正如Amandan指出的那样,在当时的调用中重新渲染起作用了:

class Booking < ApplicationRecord
 belongs_to :course , :optional => true
 belongs_to :event, :optional => true

 serialize :notification_params, Hash
  def paypal_url(return_path)
  values = {
    business: "merchant@gmail.com",
    cmd: "_xclick",
    upload: 1,
    return: "#{Rails.application.secrets.app_host}#{return_path}",
    invoice: id,
    amount: course.course_fee,
    item_name: course.title,
    item_number: course.id,
    quantity: '1',
    notify_url: "#{Rails.application.secrets.app_host}/hook"
  }
  "#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + 
  values.to_query
 end
end

}),

0 个答案:

没有答案