1

TreeStore に読み込まれる静的な JSON ファイルを取得しようとしているだけで、髪を引き裂いています。

私はモデルを持っています:

Ext.define('pronghorn_ui_keyboard.model.CommandKey', {
    extend: 'Ext.data.Model',
    fields: [
        {
            name: 'id'
        },
        {
            name: 'key'
        },
        {
            name: 'command'
        }
    ]
});

私は TreeStore を持っています:

Ext.define('pronghorn_ui_keyboard.store.Commands', {
    extend: 'Ext.data.TreeStore',

    requires: [
        'pronghorn_ui_keyboard.model.CommandKey'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            storeId: 'commands',
            model: 'pronghorn_ui_keyboard.model.CommandKey',
            proxy: {
                type: 'ajax',
                url: 'commands.json',
                reader: {
                    type: 'json'
                }
            }
        }, cfg)]);
    }
});

そして、commands.json に次の JSON があります。

{
    id: 'root',
    key: null,
    command: null,
    children: [
        {
            id: 't'
            key: 't'
            command: null,
            children: [
                {
                    id: 'te'
                    key: 'e'
                    command: 'Trade Equity'
                    leaf: true
                }
            ]
        }
    ]
}

I'm trying to programmatically load this tree and inspect it in the console. In the Controller init function:

var me = this;

me.getCommandsStore().load({
    callback: function() {
        me.rootCommandKey = me.getCommandsStore().getRootNode();
        me.currentCommandKey = me.rootCommandKey;
        console.log(me.currentCommandKey);
        console.log(me.currentCommandKey.id);
        console.log(me.currentCommandKey.hasChildNodes());
        me.initMainCommands();
    },
    scope: me
});

The console has something for currentCommandKey, but the ID isn't my root ID, and hasChildNodes() is false. So obviously the file isn't being loaded.

What am I doing wrong?

4

1 に答える 1

1

JSON が無効でした。基本的にコンマがありません。

正しい JSON は次のとおりです。

{
    success: true,
    children: [
        {
            string: 't',
            key: 't',
            command: null,
            children: [
                {
                    string: 'te',
                    key: 'e',
                    command: 'Trade Equity',
                    leaf: true
                }
            ],
            leaf: false
        }
    ]
}

非同期呼び出しでもエラー処理を改善する必要があります。一連のものを Store 自体のメソッドに移動し、ローカル バインディングを使用してその初期状態を load イベントにバインドしました。これにより、一連の load-terinating-condition フラグが公開されました。

于 2013-03-30T02:57:18.283 に答える