如何在导出const LANDMARK中获取json数据:Landmark [] = this.myobj;使用nativscript

时间:2018-07-08 15:16:13

标签: angularjs json nativescript

我正在调用一个给我一个JSON数组的API,所以我想将返回的数据分配给LANDMARKS变量。

源代码:

export const LANDMARKS : Landmark[] = this.myobj;
   console.log(this.myItems);


 fetch('https://jsonplaceholder.typicode.com/users')
    .then(response => response.json())
    .then(json => {this.myItems =  json;

  console.log(this.myItems);
        **const myobj = this.myItems**
  // return myobj;
}

  );

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

export const LANDMARKS: Landmark[] = [];

fetch('https://jsonplaceholder.typicode.com/users')
    .then(response => response.json())
    .then(json => {
        var myItems = json;
        this.LANDMARKS = myItems;
        console.log('--Landmark List--',this.LANDMARKS);
    });