有点尴尬。但是经过一番研究(我应该事先做过:P),我得到了答案。
可以使用ValueConverter完成,如下所示:http ://jdanyow.github.io/aurelia-converters-sample/ 。
而且我认为这很酷。
现在我的代码如下:
<div if.bind="errors | hasPropertyValue:'Key':'car.Model'"> <span repeat.for="error of errors | filterOnProperty:'Key':'car.Model'"> <span>${error.Message} </span> </span></div>
我在Typescript(
valueconverters.ts)中定义了几个valueconverters :
export class FilteronPropertyValueConverter {toView(array: {}[], property: string, exp: string) { if (array === undefined || array === null || property === undefined || exp === undefined) { return array; } return array.filter((item) => item[property].toLowerCase().indexOf(exp.toLowerCase()) > -1);}}export class HasPropertyValuevalueConverter {toView(array: {}[], property: string, exp: string) { if (array === undefined || array === null || property === undefined || exp === undefined) { return false; } return array.filter((item) => item[property].toLowerCase().indexOf(exp.toLowerCase()) > -1).length > 0;}}
最后,我认为这些是导入的:
<import from="yourPath/valueconverters"></import>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)