2017-10-19 99 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

谢谢,它完美地工作! –