AngularJS Typescript grid ui - 将函数设置为列值

时间:2016-06-22 07:51:24

标签: javascript angularjs typescript

我的angularJS应用程序中有以下ui网格“

this.resultGrid = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    enableHorizontalScrollbar: 0,
    enableSorting: true,
    columnDefs: [
        { name: 'Id', field: 'id' },
        { name: 'Name', field: 'name' },
        { name: 'Street', field: 'street' },
        { name: 'Postcode', field: 'postcode' },
        { name: 'City', field: 'city' },
        { name: 'Country', field: 'country' },
        { name: 'In System', field: 'inSys()' }
    ],
    data: [{ city: "Warsaw", country: "Poland", id: "123456789", name: "Company 1", postcode: "00-122", street: "Waszyngtona", inSys: this.inSys(id); }, //compilation error - cannot find name "id"
{ city: "London", country: "UK", id: "987654321", name: "Company 2", street: "Downtown" }]
};

以及我想在此控制器内调用的函数:

inSys = (id: string) => {
    if (id== null || id.length == 0)
        return false;

    return this.myService.recordExistsInSys(id);
}

我还没有找到任何关于如何在typescript中将函数作为ui-grid列值传递的示例。任何想法如何处理它?<​​/ p>

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,对我来说这很有用:

this.resultGrid = {
    enableRowSelection: true,
    enableRowHeaderSelection: false,
    enableHorizontalScrollbar: 0,
    enableSorting: true,
    context: {
          inSys: (row) => {
              /*do something with row*/
    }
    columnDefs: [
        { name: 'Id', field: 'id' },
        { name: 'Name', field: 'name' },
        { name: 'Street', field: 'street' },
        { name: 'Postcode', field: 'postcode' },
        { name: 'City', field: 'city' },
        { name: 'Country', field: 'country' },
        { name: 'In System', field: 'context.inSys(MODEL_COL_FIELD)' }
    ],
    data: [{ city: "Warsaw", country: "Poland", id: "123456789", name: "Company 1", postcode: "00-122", street: "Waszyngtona", inSys: this.inSys(id); }, //compilation error - cannot find name "id"
{ city: "London", country: "UK", id: "987654321", name: "Company 2", street: "Downtown" }]
};

我没有尝试你的代码,但也许这可以帮到你。