小编mic*_*bcn的帖子

访问要在React Native Text组件中显示的对象数组

我在访问JSON数据中的对象数组时遇到问题,无法在React Native Text组件中显示.

JSON数据

{
    "name": "Pizza Joint",
    "when": [{
        "day": ["Sat", "Sun"],
        "start_time": "11:00",
        "end_time": "23:00"
    }]
}
Run Code Online (Sandbox Code Playgroud)

<View style={styles.container}>
    <Text style={styles.name}>{venue.name}</Text>
    <Text style={styles.time}>{venue.when[0].start_time}</Text>
</View>
Run Code Online (Sandbox Code Playgroud)

这会抛出Undefined is not an object (evaluating 'venue.when')console.log(type of venue.when)返回以来我不理解的错误object.

如何when在此处访问对象属性?

补充说明

我复制了本教程中的app结构.

这是VenueList.js:

'use strict';

var React = require('react-native');
var VenueDetail = require('./VenueDetail');

var {
    Image,
    StyleSheet,
    Text,
    View,
    Component,
    ListView,
    TouchableHighlight,
    ActivityIndicatorIOS
   } = React;

var styles = StyleSheet.create({
    container: …
Run Code Online (Sandbox Code Playgroud)

javascript json reactjs react-native

7
推荐指数
1
解决办法
1万
查看次数

对Elasticsearch日期字段进行基于脚本的排序

我刚刚开始使用Elasticsearch,并且想在映射为dateformat 的字段上使用基于脚本的排序hour_minute。每个文档中可以有该字段的多个实例。

在介绍表达式之前,首先,我要尝试一种简单的排序(使用Sense插件):

POST myIndex/_search
{
   "query": {
      "match_all": {}
   },
   "sort": {
      "_script": {
         "script": "doc[\"someTime\"].value",
         "lang": "groovy",
         "type": "date",
         "order": "asc"
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误(片段):

SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
shardFailures {[tjWL-zV5QXmGjNlXzLvrzw][myIndex][0]:
SearchParseException[[myIndex][0]: 
query[ConstantScore(*:*)],from[-1],size[-1]: Parse Failure [Failed to parse source…
Run Code Online (Sandbox Code Playgroud)

如果我发布上述查询"type": "number"没有错误,尽管这当然不会按日期排序。以下工作正常:

POST myIndex/_search
{
   "query": {
      "match_all": {}
   },
   "sort": {
      "someTime": {
         "order": "asc"
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

最终,我想使用基于脚本的排序方式,因为我将尝试使用日期和时间条件进行查询,过滤或排序,例如查询具有当前日期的文档,然后按照现在之后的最短时间进行排序,等等

任何建议将不胜感激。

sorting datetime date elasticsearch

4
推荐指数
1
解决办法
8286
查看次数