return items.join('');
}
+ this.j2d = function(url) {
+ var rows = $('<table>');
+ var count = 0;
+
+ $.getJSON(url, function(json) {
+
+ $.each(json, function(i,rec){
+
+ $.each(rec, function(k,v){
+ var row = $('<tr>',{'class':k}).appendTo(rows);
+
+ $('<th>',{'text':k}).appendTo(row)
+ $('<td>',{'text':v}).appendTo(row)
+//console.log(rec);
+ });
+
+ count++;
+ });
+
+ });
+
+ return rows;
+ }
+
+ this.j2t = function(url) {
+ var rows = $('<table>');
+ var count = 0;
+
+ $.getJSON(url, function(json) {
+
+ $.each(json, function(i,rec){
+ var row = $('<tr>').appendTo(rows);
+
+ if (!count) {
+ $.each(rec, function(k,v){
+ $('<th>',{
+ 'text': k,
+ 'class': k,
+ }).appendTo(row)
+ });
+ row = $('<tr>').appendTo(rows);
+ }
+
+ $.each(rec, function(k,v){
+ $('<td>',{
+ 'text': v,
+ 'class': k,
+ }).appendTo(row)
+//console.log(rec);
+ });
+
+ count++;
+ });
+
+ });
+
+ return rows;
+ }
+
this.j2h = function(url,dest,tag='ul',map) {
var tags = {
if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.');
//console.log(tags[tag]); return;
+ var rows = $('<'+tag+'>');
+
$.getJSON(url, function(json) {
- var rows = $('<'+tag+'>');
+ if (dest) $(dest).append(rows);
tag == 'select' && rows.append($('<'+tags[tag]+'>').text(''));
//if (typeof map != 'undefined') { json = $.map(json,map); }
$.each(json, function(k, v){
- if ($.type(v) == 'object') { v = $.map(v,function(v,k){return v})[0]; v = [v,v]; }
- if ($.type(v) == 'string') v = [v,v];
- if (v.length==1) v = [v[0],v[0]]
+ if (typeof map == 'undefined') {
+ if ($.type(v) == 'object') { v = $.map(v,function(v,k){return v})[0]; v = [v,v]; }
+ if ($.type(v) == 'string') v = [v,v];
+ if (v.length==1) v = [v[0],v[0]]
+ }
var row = null;
var item;
//if (row == null) return;
- item.text(v[0]);
- item.attr('value',v[1]);
+ if (typeof map == 'undefined') {
+ item.text(v[0]);
+ item.attr('value',v[1]);
+ }
+
if (typeof map != 'undefined') { (map)(item,v); }
//if (tags[tag] == 'td') row = $('<tr>').append(row);
//if (typeof map != 'undefined') { $.each(row,map); }
- else {
- }
rows.append(row);
});
- $(dest).append(rows);
-
});
+ return rows;
}