0

私はextjsを初めて使用します。これで誰か助けてください。

ツリー パネルのアイテムをダブルクリックすると、ツリー パネルを変更せずにグリッド パネルに追加する必要があります。

4

1 に答える 1

1

ツリーパネルに「itemdblclick」イベントのリスナーを配置して、ダブルクリックされたアイテムの生のプロパティからデータを取得できます。次に、基礎となるグリッドのストアへの参照を使用して、ストアの「loadRawData」メソッドを使用してそのデータ オブジェクトを追加します。以下は、Sencha の Web サイト サンプルに基づくコード サンプルです。

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
        children: [
            { text: "School Friends", expanded: true, children: [
                { text: "Mike", leaf: true, name: "Mike", email: "mike@stackoverflow.com", phone: "345-2222"},
                { text: "Laura", leaf: true, name: "Laura", email: "laura@stackoverflow.com", phone: "345-3333"}
            ] },
            { text: "Facebook Friend", expanded: true, children: [
                { text: "Steve", leaf: true, name: "Steve", email: "steve@stackoverflow.com", phone: "345-2222"},
                { text: "Lisa", leaf: true, name: "Lisa", email: "lisa@stackoverflow.com", phone: "345-3333"}
            ] },
        ]
    }
});

Ext.create('Ext.tree.Panel', {
    title: 'All My Friends',
    width: 200,
    height: 150,
    store: store,
    rootVisible: false,
    renderTo: Ext.getBody(),
    listeners : {
            itemdblclick : function(tree, record, index){
                Ext.getStore('simpsonsStore').loadRawData([record.raw], true);
            }
    }
});

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Best Friends',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});
于 2013-07-20T21:18:20.117 に答える