return items.join('');
}
- this.j2h = function(url) {
- var tag = 'select';
+ this.j2h = function(url,dest,tag='ul',map) {
+
var tags = {
+ 'table' : 'tr.td',
'select' : 'option',
'ul' : 'li',
}
- $.getJSON(url, function(json){
- var select = $('<'+tag+'>');
- $('#nb-msg').append(select);
- tag == 'select' && select.append($('<'+tags[tag]+'>').text("Select"));
+ var m;
+ if (m = tag.match(/^(\w+)\.(.*)$/)) {
+ tag = m[1];
+ tags[m[1]] = m[2];
+ } else if(typeof tags[tag] == 'undefined' || tags[tag] == null) {
+ tags[tag] = tag;
+ }
+
+ if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.');
+//console.log(tags[tag]); return;
+
+ $.getJSON(url, function(json) {
+ var rows = $('<'+tag+'>');
+ tag == 'select' && rows.append($('<'+tags[tag]+'>').text(''));
+
+ //if (typeof map != 'undefined') { json = $.map(json,map); }
+ //console.log(json.toSource());
+
+ $.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]]
+
+ var row = null;
+ var item;
+ $.each(tags[tag],function(i,t){
+//console.log(t+': '+row);
+ item = $('<'+t+'>');
+ if (row == null) {
+ row = item;
+ } else {
+ row.append(item);
+ }
+ });
+ //row = $('<'+tags[tag]+'>');
+
+ //if (row == null) return;
+
+
+ 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);
- $.each(json, function(i, obj){
- select.append($('<'+tags[tag]+'>').text(obj.name).attr('value', obj.name));
});
+ $(dest).append(rows);
+
});
+
}
this.json2html = function(url) {
};
/*
+ Statics
*/
-
+NB.get_http = NB.prototype.get_http
+NB.dump = NB.prototype.dump
+NB.urlParam = NB.prototype.urlParam
+//NB.prototype.test = function(v) { console.log(v)}
+//NB.test = function() { console.log(that.dump('zaza'))}
//NB.prototype.your_method = function() { }