自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。

2010年4月27日火曜日

SmartGWT JSON使用例

SmartGWTフレームワークでJSON形式データを取り込む機能を紹介します。

実行画面:


ソース:
DataSource dataSource = new DataSource(); 
dataSource.setDataFormat(DSDataFormat.JSON); 
dataSource.setDataURL("/test.txt"); 

DataSourceTextField continentField = new DataSourceTextField("continent", "Continent");
DataSourceTextField nameField = new DataSourceTextField("name", "Name");
DataSourceTextField datacodeField = new DataSourceTextField("datacode", "Datacode");
dataSource.setFields(continentField, nameField, datacodeField);

ListGrid grid = new ListGrid(); 
grid.setDataSource(dataSource); 
grid.setWidth100();
grid.setHeight(150); 
grid.setAutoFetchData(true); 
grid.draw();        

test.txt
[
    {
        continent:"North America",
        name:"Bermuda",
        datacode:"BD",
        total_area:50,
        population:62099,
        gdp_total:1700,
        government:"dependent territory of the UK",
        capital:"Hamilton"
    },
    {
        continent:"North America",
        name:"United States",
        datacode:"US",
        total_area:9372610,
        population:266476278,
        gdp_total:7247700,
        indep_date:new Date(-6106035600000),
        government:"federal republic",
        capital:"Washington"
    },
    {
        continent:"Europe",
        name:"Monaco",
        datacode:"MN",
        total_area:1.9,
        population:31719,
        gdp_total:788,
        indep_date:new Date(-17387884800000),
        government:"constitutional monarchy",
        capital:"Monaco"
    },
    {
        continent:"Europe",
        name:"Norway",
        datacode:"NO",
        total_area:324220,
        population:4383807,
        gdp_total:106200,
        indep_date:new Date(-2025450000000),
        government:"constitutional monarchy",
        capital:"Oslo"
    }
]

0 件のコメント:

コメントを投稿

ホームページ