I
I
ivandao2019-07-16 17:44:16
JavaScript
ivandao, 2019-07-16 17:44:16

How to use import?

Хочу использовать JSONPath на фронтэнде.
Скачал jsonpath.min.js, подключил его в index.html (нужно ли это?).
В файле со скриптом (index.js) есть json'ы к которым я хочу обращаться при помощи jsonpath.
Может нужно его как-то импортировать?
Как мне его подключить и использовать? В Readme.md приведен пример только для node.js
Подскажите, с меня как всегда

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2019-07-16
@ivandao

Downloaded jsonpath.min.js, included it in index.html (is it necessary?).

They did everything right, so it is also possible. After that, you should have a global variable available jsonpath- refer to it:
var cities = [
  { name: "London", "population": 8615246 },
  { name: "Berlin", "population": 3517424 },
  { name: "Madrid", "population": 3165235 },
  { name: "Rome",   "population": 2870528 }
];

var jp = jsonpath; //  для краткости
var names = jp.query(cities, '$..name');
console.log(names); // [ "London", "Berlin", "Madrid", "Rome" ]
Fiddle
Well, in general, sooner or later you still have to learn how to use modules and assemblers - for example, Webpack.

D
dollar, 2019-07-16
@dollar

Modules
What is export default/import in js?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question