简体   繁体   English

React Native-FlatList排序而不对数据进行排序

[英]React Native - FlatList ordering without sorting data

Is there a way to render Flatlist rows in a certain order without sorting the data source? 有没有一种方法可以按一定顺序呈现Flatlist行而不对数据源进行排序?

Example

<FlatList
  data={[{key: 'a'}, {key: 'c'}, {key: 'b'}]}
  renderItem={({item}) => <Text>{item.key}</Text>}
/>

The above code renders a list 上面的代码呈现了一个列表

a
c
b

Is there a way to get it to render the following without sorting the data source? 有没有一种方法可以在不对数据源进行排序的情况下呈现以下内容?

a
b
c

Basically you are saying, I want Pizzar, but do not use sausage, meat, whatever. 基本上你是说,我要披萨,但不要用香肠,肉。 The answer is therefore No. 因此,答案是否定的。

In order to perform efficient sorting and ordering, you can try linq.js 为了执行有效的排序和排序,您可以尝试linq.js

linq.js, in short is LINQ for JavaScript. linq.js,简而言之是LINQ for JavaScript。 Some particular useful/pertinent features include: 一些特别有用/相关的功能包括:

  • implement all .NET 4.0 methods and many extra methods (inspiration from Rx, Achiral, Haskell, Ruby, etc...) 实现所有.NET 4.0方法和许多其他方法(来自Rx,Achiral,Haskell,Ruby等的启发)
  • complete lazy evaluation 完整的懒惰评估
  • binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense 绑定JavaScript(RxJS)和IntelliSense的反应性扩展

If Linq.JS can solve your performance issue, you should sort it first and then render the sorted data source. 如果Linq.JS可以解决您的性能问题,则应首先对其进行排序,然后再呈现排序后的数据源。

Another option is to use lodash, whose performance is claimed to be even better, see this link for details. 另一种选择是使用lodash,其性能据称甚至更好,有关详细信息,请参见此链接

在此处输入图片说明

Here are the code snippets to sort some data: LINQ.JS: 以下是对一些数据进行排序的代码段:LINQ.JS:

var queryResult = $.Enumerable.From(jsonArray)
  .OrderBy(function(x) {
    return x.user.screen_name
  })
  .Select(function(x) {
    return x.user.screen_name + ':' + x.text
  })
  .ToArray();

Lodash: Lodash:

var queryResults = _.chain(jsonArray)
.sortBy(function (x) { return x.user.screen_name })
.map(function(x) {
    return x.user.screen_name + ':' + x.text
  })
.value();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM