Aurelia获得价值召集人的结果 [英] Aurelia get value conventer results in view
问题描述
我想获得value conventer的结果,在我的视图中过滤数组以显示找到的结果数。
I would like to get the result of value conventer that filters an array in my view in order to display the number of results found.
<div repeat.for="d of documents|docfilter:query:categories">
<doc-template d.bind="d"></doc-template>
</div>
我既不想将此逻辑移动到我的控制器(保持清洁),也不想添加拐杖比如从值控制器返回一些数据。
I neither want to move this logic to my controller (to keep it clean), nor to add crutches like returning some data from the value controller.
所以,基本上我想要的东西喜欢角度优惠:
如图所示此处:
ng-repeat = filterItems中的项目=(项目|过滤器:关键字)
或此处 : ng-repeat =item in items | filter:keyword as filteredItems
So, basically I would like something like angular offers:
Like shown here:
ng-repeat="item in filteredItems = (items | filter:keyword)"
or here: ng-repeat="item in items | filter:keyword as filteredItems"
不幸的是,在Aurelia:
Unfortunately, in Aurelia:
d of filteredDocuments = documents | docfilter:query:categories
实际上是指 d
filteredDocuments = documents | docfilter:query:categories
,如果我添加括号或为
,它将无法运行(使用解析器失败)错误)。
actually means d of
filteredDocuments = documents |docfilter:query:categories
, and if I add brackets or as
, it won't run (fails with a parser error).
是否有一种简洁的方法可以将数据从数据过滤器中查看?
Is there a clean way of getting data out of data-filter in view?
祝你好运,Alexander
Best regards, Alexander
export class DocfilterValueConverter {
toView(docs, query, categories, objectToPassCount) {
...
objectToPassCount.count = result.length;
...
});
});
UPD 2.实际上,我错了: d
filteredDocuments = documents | docfilter:query:categories
。它没有解决问题但是这段代码的作用是:
1) filteredDocuments = documents | docfilter:query:categories
在init
2) d of filteredDocuments
这是在最开始的数组上重复过滤
UPD 2. Actually, I was wrong about this: d of
filteredDocuments = documents |docfilter:query:categories
. It does not solve the issue but what this code does is :
1) filteredDocuments = documents |docfilter:query:categories
on init
2) d of filteredDocuments
which is a repeat over the filtered at the very beginning array
推荐答案
假设你有一个外部元素,你可以将过滤后的项目填充到这样的特殊属性中:
Assuming you have an outer-element, you can stuff the filtered items into an ad-hoc property like this:
<!-- 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表达式>
I know this isn't exactly what you're looking for but it will do the job. I'm looking into whether it would be helpfull to add a let
binding command- something like this: <div let.foo="some binding expression">
这里的东西更好一些:
https://gist.run/?id=1847b233d0bfa14e0c6c4df1d7952597
Here's something a bit nicer: https://gist.run/?id=1847b233d0bfa14e0c6c4df1d7952597
<template>
<ul with.bind="myArray | filter">
<li repeat.for="item of $this">${item}</li>
</ul>
</template>
这篇关于Aurelia获得价值召集人的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!