G
G
GrimJack2017-08-13 14:52:01
JavaScript
GrimJack, 2017-08-13 14:52:01

How to make complex filters in js?

I am writing a project in vue.
With js with grief in half, but I can do something without jquery.
Interested in how to repeat such filters as here on the site stomportal.kz
As I understand it:
There is an array in which posts are stored by objects ([{title:'post1'},{title:'post2'}])
Each post has a properties object
And let 's say it looks like this www.jsoneditoronline.org/?id=a9bb41e2e23b75260c13e...

For the league of laziness
[
  {
    "title": "post1",
    "properties": {
      "date": "date1",
      "time": "time1",
      "services": [
          "sevice1", "service2"
        ]
    }
  },
  {
    "title": "post2",
    "properties": {
      "date": "date2",
      "time": "time2",
      "services": [
          "sevice4", "service2"
        ]
    }
  },
  {
    "title": "post3",
    "properties": {
      "date": "date1",
      "time": "time3",
      "services": [
          "sevice1", "service3"
        ]
    }
  },
  {
    "title": "post4",
    "properties": {
      "date": "date3",
      "time": "time2",
      "services": [
          "sevice3", "service4"
        ]
    }
  }
]


And I want to get only posts that match the filter:
{
  "date": "date1",
  "time": "time2",
  "services": [
    "sevice4"
  ]
}

I tried to find it on the Internet, but I didn’t find anything, neither for vue nor for just js
. Perhaps there are ready-made libraries like isotope (in general, I planned to just add a custom filter to it, but I realized that I didn’t have enough brains how to turn it or google it).
I ask the gurus for help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2017-08-13
@Stalker_RED

data.filter(item=>(
  item.properties.date === "date1" &&
  item.properties.time === "time2" &&
  item.properties.services.indexOf("sevice4") !== -1
))

E
Evgeny Kulakov, 2017-08-13
@kulakoff Vue.js

https://codepen.io/kerf/pen/VzzNYd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question