【问题标题】:How to use fully functioning JsonPath in angular 2+?如何在 Angular 2+ 中使用功能齐全的 JsonPath?
【发布时间】:2020-12-11 21:31:29
【问题描述】:

我关注了https://www.npmjs.com/package/jsonpath。尝试了一种包含外部 js 文件的方法,但没有运气。

【问题讨论】:

    标签: jsonpath angular10


    【解决方案1】:

    import jsonPath 工作后 -

    import * as jsonPath from 'jsonpath/jsonpath';
    

    JsonPath 长毛绒也适用于JSONPath-plus,这与 Jsonpath 相同。我有以下对我有用的编码 sn-p-

    安装 JSONPath-plus

    npm install jsonpath-plus
    

    angular.json 文件

    "scripts": [
        "node_modules/jsonpath-plus/dist/index-umd.js",
        "src/assets/js/jsonpath.js"
    ]
    

    jsonpath.js 有以下代码 -

    function jsonPath() {
      return JSONPath;
    }
    

    现在在 ts 文件中使用这个函数,像下面这样声明它 -

    declare const jsonPath: any;
    // use it like
     jsonPath().JSONPath(path, json);
    
     
    

    【讨论】:

      猜你喜欢
      • 2017-06-18
      • 2018-12-24
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      相关资源
      最近更新 更多