我正在创建一个库存小部件:http://jsfiddle.net/thetuneupguy/h6RB8/
$(function() {
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.quotes%20WHERE%20symbol%20in(%22GCF14.CMX%22%2C%22SIF14.CMX%22%2C%22PAH14.NYM%22%2C%22PLF14.NYM%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=', function(data) {
console.log(data.query.results.quote);
$.each(data.query.results.quote,function(key,val){
var items = [];
$.each(val,function(name,value){
items.push('<li>' +name+ ' : '+ value + '</li>');
});
$('<ul/>', {'class': 'my-new-list',html: items.join('')}).appendTo('#blk-1');
});
});
});
我想知道是否有更好的方式来显示我的结果,以便我可以格式化/设置它们以使它们适合我的小部件设计。谢谢!
答案 0 :(得分:0)
http://answers.squarespace.com/questions/3388/how-can-i-access-and-style-json-content
答案 1 :(得分:0)
看起来没人理解你的xD。你有:
$.each(data.query.results.quote, function(key, obj){
var $tr = $('<tr/>', {'class': 'my-new-list'}).appendTo('#blk-1 table');
$tr.append($('<td/>').text(obj.Name || "-"));
$tr.append($('<td/>').text(obj.Ask || "-"));
$tr.append($('<td/>').text(obj.Bid || "-"));
$tr.append($('<td/>').text(obj.Change || "-"));
$tr.append($('<td/>').text(obj.ChangeinPercent || "-"));
});
如您所见,我们不会遍历列数,因为我们在表标题中已经明确定义了这些列
来自玻利维亚拉巴斯的欢呼声