您的位置:首页 > Web前端 > JavaScript

[TypeScript] TypeScript对象转JSON字符串范例

2015-07-07 14:16 645 查看

[TypeScript] TypeScript对象转JSON字符串范例

Playground

http://tinyurl.com/njbrnrv

Samples

class DataTable {

public columns: Array<string> = new Array<string>();

public rows: Array<DataRow> = new Array<DataRow>();
}

class DataRow {

public cells: Array<string> = new Array<string>();
}

class Test {

public run() {

var table = new DataTable();
table.columns.push("ColumnA");
table.columns.push("ColumnB");
table.columns.push("ColumnC");

var row1 = new DataRow();
row1.cells.push("A1");
row1.cells.push("B1");
row1.cells.push("C1");
table.rows.push(row1);

var row2 = new DataRow();
row2.cells.push("A2");
row2.cells.push("B2");
row2.cells.push("C2");
table.rows.push(row2);

alert(JSON.stringify(table));
}
}

var test = new Test();
test.run();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: