0
有沒有一種方法可以在保存模型時顯示加載模板。Ember loader on Model save
我能夠在轉換到不同路由時使用應用程序級別加載模板,但當此時保存模型時,加載模板不會顯示。
this.transitionTo('routeName')將您帶到loading.hbs,直到它從服務器獲得承諾,但在執行model.save()時它不顯示。
有沒有一種方法可以在保存模型時顯示加載模板。Ember loader on Model save
我能夠在轉換到不同路由時使用應用程序級別加載模板,但當此時保存模型時,加載模板不會顯示。
this.transitionTo('routeName')將您帶到loading.hbs,直到它從服務器獲得承諾,但在執行model.save()時它不顯示。
loading and error substates僅在加載路由時使用。在控制器操作期間無法調用它們(除非該操作加載新的路由,但在這種情況下,狀態仍然與加載新路由而不是操作綁定)。
通過使用屬性和部分執行動作時,可以仍然顯示加載的模板:
模板:
<!-- templates/components/user-account.hbs -->
{{#if busy}}
{{partial 'loading-template-name'}}
{{else}}
{{!-- template content --}}
<button {{action "save"}}>Save</button>
{{/if}}
組分:
// components/user-account.js
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
save: function() {
if (this.get('busy')) {
return;
}
this.get('user').save()
.then(() => {
// handle success
})
.catch((e) => {
// handle error
})
.finally(() => {
this.set('busy', false);
});
},
},
})
裝載子狀態將只有在'beforeModel,'model'或'afterModel'返回一個promise時纔會顯示,如果你想在模型保存過程中顯示某些內容,則必須處理顯示一個自定義加載器 –