我正在使用semantic-ui,它有自己的內置模態功能(see here)。與其編寫所有代碼以在Aurelia中利用此特定功能,是否有辦法掛鉤aurelia-dialog插件的渲染管道,以便我可以使用配置aurelia-dialog插件來使用semantic-ui?使用帶引導程序,語義或其他ui工具包的aurelia對話框
回答
是的,有。
Aurelia-dialog提供了一個抽象的Renderer接口,它用來與渲染器接口。默認情況下,它會使用它提供的渲染器,但你可以通過配置對話框插件覆蓋此,像這樣:
import {MyRenderer} from './my-renderer';
aurelia.use.plugin('aurelia-dialog', (config) => {
config.useRenderer(MyRenderer);
});
...其中MyRenderer
使用abstract Renderer interface。在渲染器中,您需要實現三種方法:getDialogContainer
,showDialog
和hideDialog
。
有些注意事項 - 在您的showDialog
函數中,您需要創建showDialog
和hideDialog
方法並將它們附加到作爲參數傳遞的dialogController。這可以確保您的dialogController可以編程方式關閉對話框。
在實現並註冊了渲染器後,對話框插件將使用您選擇的UI工具包。希望這可以幫助。
這是我的解決方案(在TypeScript中)的語義UI模塊,它不使用aurelia對話框。
的視圖(/ui/dialogs/dialog-confirm.html):
<template>
<div class="ui modal small" ref="dialogElement">
<div class="header">${model.headerText}</div>
<div class="content">
<p>${model.messageText}</p>
</div>
<div class="actions">
<div class="ui approve button">${model.confirmText?model.confirmText:'OK'}</div>
<div class="ui cancel button">${model.cancelText?model.cancelText:'Cancel'}</div>
</div>
</div>
</template>
視圖模型(/ui/dialogs/dialog-confirm.ts):
export class Dialog {
model;
done;
result;
dialogElement:HTMLElement;
activate(data) {
if(data){
this.model = data.model;
this.done = data.done;
this.result = false;
}
}
bind(){
$(this.dialogElement)
.modal({
onApprove :()=>{ this.result = true; },
onDeny :()=>{ this.result = false; },
onHide :()=>{ this.done(this.result); }
})
.modal('show');
}
}
對話框類(/ui/dialogs/dialog.ts):
import { inject } from 'aurelia-framework';
import { EventAggregator } from 'aurelia-event-aggregator';
@inject(EventAggregator)
export class Dialog {
constructor(private eventAggregator) {
}
show(viewName: string, model) {
return new Promise((resolve, reject) => {
this.eventAggregator.publish('showDialog', {
viewName: viewName,
model: model,
resolve: resolve
});
});
}
}
...注入EventAggregator到您的應用程序類,這增加了連接()掛鉤:
attached() {
this.eventAggregator.subscribe('showDialog', (event) => {
console.assert(!this.dialogData, "Only one dialog can be shown at any time.");
event.done = (result) => {
event.resolve(result);
this.dialogData = null;
}
this.dialogName = event.viewName;
this.dialogData = event;
});
}
...終於添加到您的app.html:
<compose if.bind="dialogData" view-model="./ui/dialogs/${dialogName}" model.bind="dialogData" view="./ui/dialogs/${dialogName}.html">
</compose>
用法,你可以給任何模型 - 視圖/視圖對作爲第一個參數的名稱:
this.dialog.show('dialog-confirm',{
headerText:'Warning!',
messageText:'When you delete stuff - it is lost',
confirmText:'Delete',
cancelText:'I better not...'
}).then(function(result){
console.log('The result is: '+result)
});
我們需要一個在babel中的解決方案!:) – Reft
只需刪除類型(:HTMLElement)並在Dialog中更新eventAggregator注入,它應該可以工作 –
- 1. Ui引導程序對話框關閉
- 2. WiX引導程序:跳過引導程序UI,先顯示MSI對話框
- 3. 引導程序的遠程模式對話框不工作
- 4. 敏捷工具包和引導程序
- 5. MSI引用來自其他位置的自定義引導程序包
- 6. 帶圖片的HTML/CSS模態對話框(Sweetalert或其他)
- 7. 用於Web應用程序的UI框架/工具包
- 8. 如何使小工具包裝包括引導程序類
- 9. 最小化或摺疊引導程序2.3.2模態對話框?
- 10. 如何在Angular UI引導對話框中使用模板?
- 11. Coral UI對話框或花崗岩UI對話框 - 需要好的教程
- 12. 使用GRUB或其他程序集引導程序連接內核
- 13. 對話框應該恢復其他應用程序或在Android的活動
- 14. 帶自定義進度對話框的應用程序崩潰
- 15. jQModal或jQuery UI對話框?
- 16. 流星中的引導程序包是否包含引導工具提示?
- 17. aurelia-cli手動引導aurelia應用程序
- 18. 帶自定義數據調用的jQuery UI對話框
- 19. 如何包括引導日曆或角2 +流星應用程序的任何其他UI日曆
- 20. jquery對話框導致其他功能不能正常工作
- 21. Caliburn.Micro的其他引導程序
- 22. 自定義程序包引導程序
- 23. 帶引導程序的邊框佈局
- 24. 在對話框或其他活動中使用ListView
- 25. jQuery UI對話框和IFRAME - 帶'on'事件處理程序
- 26. Aurelia-Polymer使用CLI工具
- 27. 帶有標籤的jQuery UI對話框
- 28. 帶確認的jQuery UI對話框
- 29. JQuery UI(帶有Javascript的對話框)
- 30. 帶引導程序網格的語義標記
這是你添加到插件的部分之一嗎? –
@MatthewJamesDavis Yup。事實上,這是一段時間 - 拉的請求可以在這裏找到(https://github.com/aurelia/dialog/pull/120)。 –
您能演示如何在您的答案中實現渲染器嗎? –