2016-08-03 4 views
0

APISを変更する必要があり、クライアントコードを変更できません。私はデータを操作すべきノードコードを含んでいます。エラー[ReferenceError: obj is not defined]私は、角度表現のAPI応答、ノードコード、スニペットを含む以下のコードを持っています。あなたはちょうどそれが未使用expiration財産を維持するために大丈夫だと仮定すると、オブジェクトにcountdownプロパティを追加することができAPIの変更結果 - オブジェクト名 - Nodej

// api response 
{ 
    "active_id": null, 
    "enabled": true, 
    "last_modified": 14700220477943, 
    "latitude": 37.235205, 
    "longitude": -121.874178, 
    "expiration": null,   // need to change this to 'countdown' 
    "location_id": "0d16" 
}, 

//node stuff 


app.get('/raw_data', (req, res) => { 
    const { swLat, swLng, neLat, neLng } = req.query; 
    axios.get(`http://newURl?bounds=${swLat},${swLng},${neLat},${neLng}`) 
    .then((apiRes) => { 
     const { data } = apiRes; 

     let newData; 

     // Manipulate the `data`, then set it to newData 

     data.obj.expiration = newData.obj.countdown; 

     res.send(data); 

     // Return the manipulated data 
     res.send(newData); 
    }) 
    .catch((err) => { 
     console.log(err); 
    }); 
}); 

//angular code uses 
{{object.counter}} // not "expiration" 

答えて

0

var obj = { 
    //... 
    "expiration": null, 
    //... 
}; 
obj.countdown = obj.expiration; 

//... 

{{obj.countdown}} 

そうしないと、あなたはちょうどあなたが必要なフィールドを持つ新しいオブジェクトを作成することができます

var obj1 = ...; 
var obj2 = { 
    countdown: obj.expiration, 
    //... 
}; 
+0

やあ、ノードでは、私はOBJの後にドットでエラーを取得しています。任意のアイデア –

+0

具体的に何がエラーですか?私のコードは例であることに注意してください。変数名を自分の変数の名前に置き換えます。 – qxz

+0

[TypeError:未定義のプロパティ 'obj'を読み取ることができません] //私自身の変数を使用しています –

関連する問題