javascript – Aurelia获得价值观的结果

我想得到值得考虑的结果,在我的视图中过滤数组,以显示找到的结果数.
<div repeat.for="d of documents|docfilter:query:categories">
    <doc-template d.bind="d"></doc-template>
  </div>

我不想将这个逻辑移到我的控制器(保持干净),也不要添加拐杖,如从值控制器返回一些数据.

我想要的是:

所以,基本上我会喜欢有角度的优惠:
如图所示here
ng-repeat =“filteredItems =(items | filter:keyword)”中的项目
here:ng-repeat =“item in items | filter:keyword as filteredItems”

我得到的

不幸的是,在Aurelia:

d的filteredDocuments = documents | docfilter:query:categories

实际上意味着d的filteredDocuments = documents | docfilter:query:categories,如果我添加了方括号或as,它将不会运行(失败与解析器错误).

所以,

有没有一种干净的方式从数据过滤器中获取数据?

最好的问候,亚历山大

UPD 1:当我谈到从价值控制器返回一些数据时,我的意思是:

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:在init上的类别
2)已经过滤的文档,这是在最开始数组过滤的重复数据

解决方法

假设你有一个外部元素,你可以将过滤的项目填充到ad-hoc属性中,如下所示:
<!-- 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>

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...