谓词数组的Angular`orderBy`过滤器问题 [英] Angular `orderBy` filter issue with predicate array

查看:68
本文介绍了谓词数组的Angular`orderBy`过滤器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎是角度顺序有问题通过滤镜或我错过了一些东西我想按多个属性排序,因此将所有属性作为字符串数组传递,并以 + -字符串开头.我有一个方法 getPredicate(),该方法解析 filterObject 并创建谓词数组( filterObject 中的键).根据 filterObject 中每个键的值,它在每个谓词之前带有 + -符号.(由于对象属性是动态的,并且属性名称很可能在它们之间包含空格,如 Updated Date ,因此必须用'将其括起来)似乎排序不正确.初始谓词看起来像 ['name'",'-Updated Date'"] .

It seems either there is an issue in angular orderBy filter or I am missing something I want to order by multiple properties hence passing all the properties as array of strings preceded by + or -strings. I have a method getPredicate() which parse the filterObject and creates array of predicates (keys in filterObject). based on value of each key in filterObject it precede each predicate with + or - sign. (since object properties are dynamic and it is quite possible property name contain space in between like Updated Date it is necessary to enclose them with ') it seems sorting is not accurate. initial predicate would look like ["'name'", "'-Updated Date'"].

这是柱塞我已经分叉了.

推荐答案

针对存在类似问题的人的解决方案,

Solution for those who have similar issue,

您必须在'(单引号)之前加前缀- + 符号,以使其正常工作,我面临的问题是我试图在'(单引号)之后加上- + 符号前缀,以便控制台打印的数组看起来像 ["+'name',"-'Updated Date',"-'city'] ,并且效果很好.

you have to prefix - or + sign before ' (single quote) in order to make it work, I was facing issue since I was trying to prefix - or + sign after ' (single quote) so console printed array will look something like ["+'name'", "-'Updated Date'", "-'city'"] and it work perfectly.

正在工作柱塞

这篇关于谓词数组的Angular`orderBy`过滤器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆