【问题标题】:Trying to update a table with sorted values using Lodash尝试使用 Lodash 更新具有排序值的表
【发布时间】:2018-03-16 01:44:56
【问题描述】:

尝试使用 Lodash 更新具有排序值的表。我找到了this 答案,我正在尝试实施。

Demo plunker 是here - 当您单击“排序”按钮时将排序后的值输出到控制台,但之后不会排序和更新表值(vm.resourceGridResources.Resources)?

代码:

var sorted = _.orderBy(results, ['Value'], ['asc']);

console.log(sorted);

//this part is not working...
var sortedCollection = _.sortBy(temp, function(item) {
    return sorted.indexOf(item.ResourceId);
});

vm.resourceGridResources.Resources = sortedCollection;

你能告诉我如何解决吗?

【问题讨论】:

    标签: javascript angularjs sorting lodash


    【解决方案1】:

    您在带有对象的数组上使用.indexOf。您可以使用来自 lodash 的findIndex

    _.findIndex(sorted, {ResourceId: item.ResourceId});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 2014-01-18
      • 2017-08-31
      相关资源
      最近更新 更多