Tak mas asi nekde spatne logiku. Kdyz to nejde, doporucuji vse zkopirovat do vedlejsiho souboru, smazat a zacit znovu. Postupne si odlad kazdy krok zvlast.
Nevim, co myslis zobrazenim cesty, ale objekt si muzes vypisovat. Jen si musis davat bacha na klicova slova jako window a pod. Tam je schopen se zacyklit pri prochazeni vsech vetsi objektu.
str = '';
for (key in x) {str += key + "\n"';}
alert(str);
Jo, uz jsem u sebe, takze pak kodu, co pouzivam v tom chatu. Pri selectu celej objekt naklonuji, protoze jinak by mi editoval zaznam v db (js tabulce s objekty). Coz nechci.
U JS je ta nevyhoda, ze nemuzes definovat, jestli ches klon objektu nebo jenom ukazatel. automaticky dava ukazatel :)
function is_object(data)
{
return typeof(data)==='object' || typeof(data)==='array';
}
function cloneObject(obj)
{
var i, new_obj;
new_obj = {};
for (i in obj)
{
if (!is_object(obj[i]))
{new_obj[i] = obj[i];}
else {new_obj[i] = cloneObject(obj[i]);}
}
return new_obj;
}
//-----
function classDb(structure)
{
this.table = [];
this.structure = structure;
this.drop = function(data)
{
this.table = [];
}
this.import = function(data)
{
var i;
this.table = data;
for(i=0;i<this.table.length;i++)
{
this.table[i].index = i;
}
}
this.export = function(data)
{
return this.table;
}
this.insert = function(data)
{
var key, new_row, index;
if (!is_object(data))
{
return;
}
index = this.table.length;
new_row = new this.structure;
for (key in new_row) //this.table[index]
{
new_row[key] = data[key] ? data[key] : '';
}
new_row.index = index;
this.table[index] = new_row;
return new_row;
}
this.update = function(where,data)
{
var row,key,value;
row = this.select(where); // read
if (row && is_object(row))
{
for(key in where)
{
value = where[key];
if (!is_null(value) && isset(row[key])) // ignore undefined
{
row[key] = value;
}
}
this.table[row.index] = row; // write
return row;
}
return false;
}
this.select = function(where)
{
var i,row,bool,key,value;
for(i=0;i<this.table.length;i++)
{
row = this.table[i];
bool = true;
for(key in where)
{
value = where[key];
if (!is_null(value) && isset(row[key])) // ignore undefined
{
bool &= row[key] == value;
if (!bool) break;
}
}
if (bool)
{
return cloneObject(row);
}
}
return false;
}
}
// ----
function classUser()
{
this.index = null; // unique autoincrement
this.id = null;
this.name = null;
this.psw = null;
this.ip = null;
this.time = null;
this.id_peer = null;
this.color = null;
}
/ ---
CHAT.users_db = new classDb(classUser);
//...
CHAT.userlist.add = function (user)
{
CHAT.users_db.insert(user);
CHAT.userlist.show();
};