Aurelia get value conventer results in 视图
Aurelia get value conventer results in view
我想获得在我的视图中过滤数组的值转换器的结果,以便显示找到的结果数。
<div repeat.for="d of documents|docfilter:query:categories">
<doc-template d.bind="d"></doc-template>
</div>
我既不想将此逻辑移动到我的控制器(以保持它的清洁),也不想添加诸如从值控制器返回一些数据之类的拐杖。
我想要的:
所以,基本上我想要 angular 提供的东西:
如图所示 here:
ng-repeat="item in filteredItems = (items | filter:keyword)"
或 here: ng-repeat="item in items | filter:keyword as filteredItems"
我得到的:
不幸的是,在 Aurelia:
d of filteredDocuments = documents|docfilter:query:categories
其实就是d of
filteredDocuments = documents |docfilter:query:categories
,如果我加上括号或者as
,就不会运行(因解析器错误而失败)。
所以,
是否有从数据过滤器视图中获取数据的干净方法?
最好的问候,亚历山大
UPD 1:当我谈到从值控制器返回一些数据时,我的意思是:
export class DocfilterValueConverter {
toView(docs, query, categories, objectToPassCount) {
...
objectToPassCount.count = result.length;
...
});
});
UPD 2. 实际上,我错了:d of
filteredDocuments = documents |docfilter:query:categories
。它没有解决问题,但这段代码的作用是:
1) filteredDocuments = documents |docfilter:query:categories
初始化
2) d of filteredDocuments
这是在最开始的数组
上重复过滤
假设您有一个外部元素,您可以将过滤后的项目填充到临时 属性 中,如下所示:
<!-- assign the filtered items to the div's "items" property: -->
<div ref="myDiv" items.bind="documents | docfilter : query : categories">
<!-- use the filtered items: -->
<div repeat.for="d of myDiv.items">
<doc-template d.bind="d"></doc-template>
</div>
</div>
我知道这不是您要找的,但它可以胜任。我正在研究添加 let
绑定命令是否有帮助 - 像这样:<div let.foo="some binding expression">
编辑
这里有一些更好的东西:
https://gist.run/?id=1847b233d0bfa14e0c6c4df1d7952597
<template>
<ul with.bind="myArray | filter">
<li repeat.for="item of $this">${item}</li>
</ul>
</template>
我想获得在我的视图中过滤数组的值转换器的结果,以便显示找到的结果数。
<div repeat.for="d of documents|docfilter:query:categories">
<doc-template d.bind="d"></doc-template>
</div>
我既不想将此逻辑移动到我的控制器(以保持它的清洁),也不想添加诸如从值控制器返回一些数据之类的拐杖。
我想要的:
所以,基本上我想要 angular 提供的东西:
如图所示 here:
ng-repeat="item in filteredItems = (items | filter:keyword)"
或 here: ng-repeat="item in items | filter:keyword as filteredItems"
我得到的:
不幸的是,在 Aurelia:
d of filteredDocuments = documents|docfilter:query:categories
其实就是d of
filteredDocuments = documents |docfilter:query:categories
,如果我加上括号或者as
,就不会运行(因解析器错误而失败)。
所以,
是否有从数据过滤器视图中获取数据的干净方法?
最好的问候,亚历山大
UPD 1:当我谈到从值控制器返回一些数据时,我的意思是:
export class DocfilterValueConverter {
toView(docs, query, categories, objectToPassCount) {
...
objectToPassCount.count = result.length;
...
});
});
UPD 2. 实际上,我错了:d of
filteredDocuments = documents |docfilter:query:categories
。它没有解决问题,但这段代码的作用是:
1) filteredDocuments = documents |docfilter:query:categories
初始化
2) d of filteredDocuments
这是在最开始的数组
假设您有一个外部元素,您可以将过滤后的项目填充到临时 属性 中,如下所示:
<!-- assign the filtered items to the div's "items" property: -->
<div ref="myDiv" items.bind="documents | docfilter : query : categories">
<!-- use the filtered items: -->
<div repeat.for="d of myDiv.items">
<doc-template d.bind="d"></doc-template>
</div>
</div>
我知道这不是您要找的,但它可以胜任。我正在研究添加 let
绑定命令是否有帮助 - 像这样:<div let.foo="some binding expression">
编辑
这里有一些更好的东西: https://gist.run/?id=1847b233d0bfa14e0c6c4df1d7952597
<template>
<ul with.bind="myArray | filter">
<li repeat.for="item of $this">${item}</li>
</ul>
</template>