2017-04-07 84 views
0

有沒有辦法將其他變量/數據從對話框服務導入控制器?將變量導入aurelia-dialog視圖模型或視圖

例如,我在我的應用程序視圖的窗體中有一個可能的選項數組。我通過服務器的API獲取數據。

我想編輯一個帶有aurelia對話框的條目,並且不想再次獲取數據以避免在我的應用中產生不必要的流量。

我該如何將數組另外傳遞給模型。將它們全部打包在一個對象中,並將其打包在控制器中? 據我所知,控制器的activate-method只需要一個參數,不是嗎?

謝謝

回答

0

存儲庫中的示例與您正在查找的不一樣嗎? person屬性通過settings對象(model: this.person)傳遞給對話服務。這可能是您從服務器獲取的數據。正如您所提到的,您當然也可以向模型中添加多個對象,這些對象將在對話框vm的activate()方法中提供。

import {EditPerson} from './edit-person'; 
import {DialogService} from 'aurelia-dialog'; 
export class Welcome { 
    static inject = [DialogService]; 
    constructor(dialogService) { 
    this.dialogService = dialogService; 
    } 
    person = { firstName: 'Wade', middleName: 'Owen', lastName: 'Watts' }; 
    submit(){ 
    this.dialogService.open({ viewModel: EditPerson, model: this.person}).then(response => { 
     if (!response.wasCancelled) { 
     console.log('good - ', response.output); 
     } else { 
     console.log('bad'); 
     } 
     console.log(response.output); 
    }); 
    } 
}