【问题标题】:Angular multiple sort, order by角度多重排序,按顺序排列
【发布时间】:2013-11-04 16:02:14
【问题描述】:

可能是一个非常愚蠢的问题,我错过了明显的问题,但我正在使用一个函数来对我的结果进行排序。 每个结果都有一个价格和一个权重(基本上是优先级)

我想要按价格排序的结果,但是有相同价格的结果,它们需要按重量排序。我也可以颠倒排序,所以低-高/高-低。

这是一个带有一些点头数据的笨蛋:

http://plnkr.co/edit/VH2WvyJMsLSTpWJawT2f?p=preview

在我的应用程序中(我有数百个结果),我使用了这个

$scope.orderByFunction = function (result) {
    if ($scope.orderBy == 'price-low-high') {
        return result.totalPrice.amount + result.boost;
    }
    if ($scope.orderBy == 'price-high-low') {
        return -result.totalPrice.amount + result.boost;
    }
    else return result.totalPrice.amount + result.boost;
};

虽然我认为它最初是成功的,但它出现了一些错误,因为它显示了价格较高的结果高于价格较低的结果。感谢我很难证明这一点,所以我想我会先问点头的问题:)

【问题讨论】:

  • 我试了一下...没有看到不规则的排序
  • 立即查看。我添加了更多结果并使用了上面的订购代码plnkr.co/edit/VH2WvyJMsLSTpWJawT2f?p=preview 价格 150 显示高于价格 100。我猜这是我的一些非常愚蠢的错误。
  • 建议你缩小重复元素大小H1??并为人们提供复制的步骤......我只是看不到它
  • 好的。请参阅:embed.plnkr.co/VH2WvyJMsLSTpWJawT2f 尝试更改下拉列表中的排序。基本上都是错的。它应该按价格排序,然后如果价格相同,则按权重排序。

标签: angularjs sorting angularjs-orderby


【解决方案1】:

已回复https://groups.google.com/forum/#!topic/angular/XAJ2hyeRSTU

这是 html http://plnkr.co/edit/VH2WvyJMsLSTpWJawT2f?p=preview orderBy: [orderByPrice, orderByPriority]

和 JS

$scope.orderByPrice = function (result) {
    if ($scope.orderBy == 'price-low-high') {
        return result.amount;
    }
    if ($scope.orderBy == 'price-high-low') {
        return -result.amount;
    }
    else return result.totalPrice.amount;
};
$scope.orderByPriority = function (result) {
        return result.priority;
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    相关资源
    最近更新 更多