我正在創建一個簡單的股票代碼,其中的符號最終將通過cms輸入。到目前爲止,我已經成功地正確獲取ajax數據,我試圖找出如何將每個符號拆分,並將相應的數據分成單獨的項目,列表項目或其他。我試圖使用.each但沒有運氣。將陣列對象拆分爲單獨的視圖
這裏是我的JS:
(function(){
var getStocks = (function(){
var initialize = function(){
_setListeners();
};
var _setListeners = function(){
var symbol = ["GOOG", "AAPL", "A", "AA", "ABT"];
$.ajax({
url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D"+symbol+"%26f%3Dnsl1d1t1c1ohgv%26e%3D.csv'%20and%20columns%3D'name%2Csymbol%2Clast_trade_price%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Ccol2'&format=json",
dataType: 'json',
success: function(data) {
console.log(data);
var name = data.query.results.row.name;
var last_trade = data.query.results.row.last_trade_price;
var last_trade_size = data.query.results.row.time;
var change = data.query.results.row.low;
$.each(data, function(index, value) {
$("#stock").append('Name:'+name+ 'Symbol:' +symbol+ 'Last Trade:' +last_trade+ 'Last Trade Size:' +last_trade_size+ 'Change:'+change);
});
},
error: function() {
$("#stock").html('<p>Something has gone terribly wrong.</p>');
}
});
};
//call initialize
return {init: initialize};
}());
//call headerNav
this.getStocks = getStocks;
}).call(this);
周杰倫,這將是有益的包括在問題中的示例json。 –
你的代碼對我來說看起來沒問題..什麼是示例輸入和輸出? –