2017-10-19 91 views
0

仍然newure Aurelia FW。 我想執行位於該父級中的模板的父頁面中的函數。這樣做我沒有問題。問題是我想獲取位於模板中的變量\屬性值,並將其用作函數中的參數。如何在父級和模板之間「共享」此屬性? 我假設綁定應該是答案。 以下是相關代碼: 這是父級中的模板實例。相關功能來運行是changeStatus呼叫功能位於父母從Aurelia參數模板

<radio-button-switch is-active.bind="account.IsEnabled" change-state- 
fuction.call="changeStatus(state)" ></radio-button-switch> 

這是在父功能:

changeStatus(statusVariable) { 
//TODO something with statusVariable} 

這是模板HTML:

<template> 
     <input type="checkbox" 
        change.delegate="changeState($event.target.checked)"> 
    </template> 

這是有關模板代碼(我想執行變更狀態函數與器isChecked作爲參數):

import { bindable } from 'aurelia-framework'; 
export class radioButtonSwitch { 
    @bindable changeStateFuction; 

    changeState(isChecked) 
    { 
     this.isElementActive = isChecked; 
     this.changeStateFuction(isChecked); 
    } 
} 

回答

1

如果我有你的權利,你需要創建「參數對象」:

如果您需要調用帶參數的功能,創建一個對象 其鍵是參數名稱,其值是參數 值,然後使用此「參數對象」調用該函數。

所以,在你的代碼應該是這樣的:

this.changeStateFuction({ status: isChecked }); 
+0

謝謝,它完美地工作! –