2017-08-14 83 views
0

我正在使用Wijmo的wjFlexGridDetail指令,并希望根据组件中的“detailData”数组是否包含任何匹配数据来控制哪些行显示详细网格。 rowHasDetail属性使用外部网格的行作为输入并返回布尔值的函数。我想要做这样的事情:将任意数据传递给子指令

<ng-template wjFlexGridDetail let-item="item" [rowHasDetail]="hasDetail"> 

hasDetail (row): boolean { 
    return this.detailData.filter(item => item.ID === row.dataItem.ID).length > 0 
} // detailData is undefined when I try this 

但是,这并不工作,因为this在函数的范围是指wjFlexGridDetail对象,其中不包含我想核对数据。我试着结合它作为数据属性:

<ng-template wjFlexGridDetail let-item="item" [rowHasDetail]="hasDetail" [attr.data-detail]="detailData"> 

,但得到了一个错误:

Uncaught (in promise): Error: Template parse errors: Property binding data-detail not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".

有另一种方式来获得这些数据到函数的范围是什么?或者专门用于wjFlexGridDetail的用法,是否有另一种方法来实现我的目标(我希望它只显示具有详细数据的行的+扩展按钮)?

回答

0

我发现了一个解决方案,但它感觉像差Angular,所以希望仍然有更好的答案。

bind函数可以将任何数据添加到函数的作用域。不是直接传入函数,而是调用一个返回函数并将数据绑定到该函数的函数。

<ng-template wjFlexGridDetail let-item="item" [rowHasDetail]="hasDetail()"><!-- note the() --> 

hasDetail(): (row) => boolean { 
    return function (row): boolean { 
     return this && this.filter(item => item.ID === row.dataItem.ID).length > 0 
    }.bind(this.detailData) 
} 

更改功能detailData的范围内允许进行比较,但它确实没有觉得做事情的“正确”的方式。