0

ツリー グリッドに json データを入力するのに苦労しています。データベースからデータを読み取り、それをツリー グリッドにロードしています。

データベースから取得した json データは、以下に示すのと同様の形式です。

{   "data": [{            
    "bike": "Yamaha",
    "color": "Black",
    "cost": 870000
},{
    "bike": "Honda",
    "color": "Red",
    "cost": 675000
},{
    "bike": "Honda",
    "color": "Blue",
    "cost": 690000
},{
    "bike": "Suzuki",
    "color": "White",
    "cost": 800000"
},{
    "bike": "Harley",
    "color": "Yellow",
    "cost": 980000
},{
    "bike": "Harley",
    "color": "Black",
    "cost": 880000
}]}

私のツリー パネルでは、最初の列はツリー列です。ツリーパネルに以下のプロパティを設定しました

                displayField: 'bike',
                rootVisible: false,
                useArrows: true,

ツリーグリッドにロードすることはできますが、各データはツリーの個別のノードに表示されます。これは、json 構造がツリーに適していないためです。

以下に示すように、jsonデータを特定の形式に変換またはネストしたい:

{"data": [{            
    "bike": "Yamaha",
    "data": [{
        "bike": "Yamaha",
        "color": "Black",
        "cost": 870000
    }]
},{
    "bike": "Honda",
    "data": [{
        "bike": "Honda",
        "color": "Red",
        "cost": 675000
    },
    {
        "bike": "Honda",
        "color": "Blue",
        "cost": 690000      
    }]
},{
    "bike": "Suzuki",
    "data": [{
        "bike": "Suzuki",
        "color": "White",
        "cost": 800000"
    }]
},{
    "bike": "Harley",
    "data": [{
        "bike": "Harley",
        "color": "Yellow",
        "cost": 980000
    }]
},{
    "bike": "Harley",
    "data": [{
        "bike": "Harley",
        "color": "Black",
        "cost": 880000
    }]
}]}

以下の出力を取得できるように..

ここに画像の説明を入力

json データの変換方法がわかりません。ウェブで適切な解決策を見つけることができませんでした。助けてください

私の店はこんな感じです。

var MyStore = Ext.create('Ext.data.TreeStore', {
        autoLoad: true,
        autoSync: true,
        storeId: 'MyStore',
        model: 'model',
        proxy: {
            type: 'ajax',
            api: {
                read: 'http://localhost/Files/data.json'
            },
            reader: {
                type: 'json',
                messageProperty: 'message',
                successProperty: 'success',
                root: 'data',
                totalProperty: 'total'
            }
        }

});

4

3 に答える 3

1

私はこれを自分で解決しました...ツリーグリッドにデータを入力するためにネストされた形式でJsonデータを取得するには、SQLクエリ自体を変更する必要がありました。

// ノード パラメータの値を取得します

$node = $_POST['node'];
if (empty($node)){
    $node = $_GET['node'];
}

// ノードのタイプに基づいて、データを照会します

if (strcmp(strtolower($node),"root")==0) {
    // If root node then query all bikes with remaining data as null for setting the parent nodes
    $query = "Select 'PARENT_' || b.id as ID, Null as color, Null as cost from Bikes b";    
} else {
    // Splitting the Id from string
    $node = explode("_", $node);
    $nodeType = $node[0];
    $bikeID = $node[1];

    if (strcmp(strtolower($nodeType),"parent")==0) {            
        // if node is a parent node, then load all child nodes based on bike ID
        $query = "select 'CHILD_' || b.id as ID, b.color as color, b.cost as cost from Bikes b where b.id = ".sprintf('%d',intval($bikeID));                    
    }
}
// execute the query
execute($query);
于 2013-10-11T09:12:58.340 に答える
0

Tree Store のルート構成はどのようになっていますか? デフォルトでは、ネストされたデータの予期されるルート プロパティは「子」ですが、(あなたの場合) 「データ」に変更できます。

于 2013-05-28T12:42:19.730 に答える