微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

原文地址:https://www.jb51.cc/js/152891.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐