如何对javascript

时间:2019-05-23 15:45:13

标签: javascript jquery arrays object

我有一个静态对象,一旦加载了静态对象,就为每个对象进行ajax调用,并用其apidata替换静态对象数据,我想知道如何使用javasript。

我首先传递了静态数据对象,一旦加载了每个对象,对于相应的id传递其apidata,如何在javascript中进行操作,我添加了部分代码

例如:if the object trans is loaded, then make ajax call and send the transapidata


//backend app.js

var express = require('express');
var app = express();
var router = express.Router();

var static =[{
  id: "trans",
  fee: 10,
  country: "SG"
},{
  id: "fund",
  fee: 20,
  country: "TH"
}]

var transapi=[{
  id: "trans",
  fee: 10,
  country: "SG",
  rate: 0.5
}]

var fundapi=[{
  id: "fund",
  fee: 15,
  country: "SG",
  rate: 1.5
}]
router.get('/en', function (req, res) {
  if(req.query.hasOwnProperty("providers")){
    res.send({transapidata: transapi,  fundapidata :fundapi})
  }
else{
  res.send({staticdata: static })
  }
}


//frontend provider.js

  var provider=[trans, fund];
  var lis = this.staticdata
constructor(){
this.static();
}
  static(){
    var li = $.ajax({
           url: "/en",
          method: 'get',
          global: false,
          async: false,
          data: {
            providers: JSON.stringify(provider)
          },
          success: function (data) {
            return data;
          }
        }).responseText;
     lis = JSON.parse(li);
    }

render(){
   this.staticdata.map((e)=>{
   <p>e.id</p>
   <h5>e.country</h5>
   <h6>e.rate</h6>
 })
}

0 个答案:

没有答案