在我的Aurelia视图中,我有一个脚本标记,我想从我的视图模型中调用一个函数:
page.html中:
<template>
...
<script>
function beginEdit(args) {
console.log(args);
console.log(args.primaryKeyValue);
//In this place I want to call the sayHello() fuction
};
</script>
</template>
Run Code Online (Sandbox Code Playgroud)
Page.js:
import {inject} from 'aurelia-framework'
import {HttpClient} from 'aurelia-http-client';
import {Router} from 'aurelia-router';
export class Licigrid{
constructor(){...}
activate(){...}
...
sayHello()
{
alert("Hello");
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在我的脚本标记内部使用,${sayHello();}但是当页面加载时不会立即调用该函数,而不是当用户输入beginEdit()函数时.
我在Plunker中复制了这段代码.
请注意,我正在使用一个自己调用beginEdit函数的包,所以不幸的是我不能在我的html标记中使用.trigger(),. delegate()或.call()来解决我的问题.
我的问题是:是否有解决方案从我的脚本标签调用sayHello()函数?