使用 extjs 存储的复杂嵌套 json 循环

Complicated nested json loops to store with extjs

我正在使用从 naturalearthdata 中提取的 geojson,它看起来像这样:

我只想捕获每个功能的名称,以便在网格中显示它们(实时搜索网格。顺便说一句,它对 2000 个名称有效吗?) 但是我无法访问所有具有 root 属性 的名称。我试图循环使用所有功能

Ext.define('myApp.store.Places', {
    extend: 'Ext.data.Store',
    alias: 'store.places',
    requires : ['myApp.model.PlacesModel',
                'myApp.view.main.MainModel'],
    id: 'Places',
    model: 'myApp.model.PlacesModel',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url : '/resources/data/coord.json',
        reader: {
            type: 'json',
            transform: {
                fn: function(data) {
                    for(var i = 0; i < data.features.length -1; i++){
                        names_places.push(data.features[i].properties.NAME);
                    }
                    debugger;
                    return names_places;
                },
                scope: this
            }
        }
    }
});

但是调试器向我发送了我不理解的结果:

尤其是当数组看起来不错时:

只抓NAME的好方法是什么? return 是否必须查找 json?

您可以使用模型定义中 fields 数组的 mapping 属性将 json 中的正确属性映射到字段。

您将 readerrootProperty 设置为 features

然后在你的 fields 数组中类似于此

fields: [
    { name: 'myCustomField', mapping: 'properties.NAME' }
]