语义UI-搜索选项为空

问题描述 投票:0回答:1

因此,我试图弄清语义UI的搜索模块的工作方式。我已经在一些测试数据上对其进行了测试:

const testdata = [
    {
    "id": 7,
    "created_at": "2020-03-24 08:40:42",
    "updated_at": "2020-03-25 10:10:59",
    "name": "NameX",
    "email": "[email protected]",
    "phone": "94860509"
    },
    {
    "id": 8,
    "created_at": "2020-03-25 10:11:10",
    "updated_at": "2020-03-25 10:11:10",
    "name": "NameY",
    "email": "[email protected]",
    "phone": "94860509"
    },
    {
    "id": 9,
    "created_at": "2020-03-31 15:55:06",
    "updated_at": "2020-03-31 15:55:19",
    "name": "Lucifer",
    "email": "[email protected]",
    "phone": "58893177"
    },
    {
    "id": 10,
    "created_at": "2020-03-31 15:55:41",
    "updated_at": "2020-03-31 15:55:41",
    "name": "Morningstar",
    "email": "[email protected]",
    "phone": "12345678"
    },
    {
    "id": 11,
    "created_at": "2020-04-01 16:13:39",
    "updated_at": "2020-04-01 16:13:39",
    "name": "Superwhale",
    "email": "[email protected]",
    "phone": "18181818"
    }
];

目前看来,它实际上是在进行搜索。其中有两个带有单词“ name”的名称-NameXNameY,这给了我两个结果,问题是这些结果只是空白。[https://i.imgur.com/O6CcAdc.png][1]

这是搜索元素的配置方式:

$('.ui.search').search({
    source: testdata,
    showNoResults: true,
    ignoreDiacritics: true,
    searchFullText: false,
    searchFields: [
        'name'
    ]
});

我已经仔细阅读了文档,似乎应该可以使用,但是没有用。我是否缺少明显的东西?

javascript json search semantic-ui
1个回答
0
投票
尝试功能

const filterNameObj = (array) => array.filter(item => { if((item.name === 'NameX') || (item.name === 'NameY')) return item }) filterNameObj(testdata )

 

const testdata = [ { "id": 7, "created_at": "2020-03-24 08:40:42", "updated_at": "2020-03-25 10:10:59", "name": "NameX", "email": "[email protected]", "phone": "94860509" }, { "id": 8, "created_at": "2020-03-25 10:11:10", "updated_at": "2020-03-25 10:11:10", "name": "NameY", "email": "[email protected]", "phone": "94860509" }, { "id": 9, "created_at": "2020-03-31 15:55:06", "updated_at": "2020-03-31 15:55:19", "name": "Lucifer", "email": "[email protected]", "phone": "58893177" }, { "id": 10, "created_at": "2020-03-31 15:55:41", "updated_at": "2020-03-31 15:55:41", "name": "Morningstar", "email": "[email protected]", "phone": "12345678" }, { "id": 11, "created_at": "2020-04-01 16:13:39", "updated_at": "2020-04-01 16:13:39", "name": "Superwhale", "email": "[email protected]", "phone": "18181818" } ]; const filterNameObj = (array) => array.filter(item => { if((item.name === 'NameX') || (item.name === 'NameY')) return item }) console.log(filterNameObj(testdata))
© www.soinside.com 2019 - 2024. All rights reserved.