使用knockout从cshmlt调用typescript函数

时间:2015-09-15 10:49:28

标签: razor knockout.js typescript

尝试使用knockout从cshtml调用typescript的remove(object:any)函数,但不能:

    module DatawareHouseApp {
        declare var rowList: string[];
        declare var colList: string[];
        declare var measuresList: string[];
        export var rowTag: Tag[];
        export var colTag: Tag[];

        export class MainPage
        {

            public RemoveFromRows(object: any)
            {
                alert("In");
                console.log(object);
            }
        }
}

CSHTML:

<ul data-bind="foreach :rowCols">
    <li>
          <span data-bind="text: text"></span>
                 <a class="tagit-close" data-bind="click: RemoveFromRows">x</a>
     </li>
</ul>

2 个答案:

答案 0 :(得分:1)

基于代码:

data-bind="click: RemoveFromRows"

您肯定希望将public RemoveFromRows(object: any) {更改为public RemoveFromRows = (object: any) => {。以下是一些more docs about arrow functions

答案 1 :(得分:0)

快速猜测。您在foreach循环的上下文中,并尝试引用全局命名空间。也许$ root.RemoveFromRows?

http://knockoutjs.com/documentation/binding-context.html

如果没有其他人帮助我,我会稍后回来扩展/排除故障。