代码之家  ›  专栏  ›  技术社区  ›  liu peng

为什么非自动加载的商店中的项目数为0?

  •  0
  • liu peng  · 技术社区  · 13 年前

    我使用的是ExtJs 4.1。

    我有一个这样的商店:

    var predictTargetStore = new Ext.create('Ext.data.Store',{
        autoLoad : false,
        fields: ['label','value'],
        proxy : {
            type : 'ajax',
            reader : {
                type : 'json',
                root : 'predictTargetList'
            }
        }
    });
    

    稍后我将执行predictTargetStore.load({url:“getPredictTargetList.action”})。完成此操作后,使用predictTargetStore的组合框将有选择。 但当我试图从商店里买到一件商品时,我失败了。我喜欢这样:

    predictTargetStore.load({
        url : 'getPredictTargetList.action'
    });
    var value = predictTargetStore.getAt(0).get('value');
    

    我发现predictTargetStore.getAt(0)为null,而predictTargetStore.getCount()为0。 那么我怎样才能买到商店里的一件商品呢? 非常感谢你!

    4 回复  |  直到 13 年前
        1
  •  1
  •   user650749    13 年前

    我试过了,下面就可以了:

    user.load({
        scope: this,
    
        callback: function(records, operation, success) {
        user.each(function(record) {
            console.log(record.get('name'));
        });
        }
    });
    
        2
  •  1
  •   user1636522 user1636522    13 年前

    等待服务器响应:

    predictTargetStore.load({
        url : 'getPredictTargetList.action',
        callback: function () {
            var value = predictTargetStore.getAt(0).get('value');
        }
    });
    

    有关的详细信息 callback 作用 here .

        3
  •  0
  •   user650749    13 年前

    我遇到了类似的问题,代码如下: `

    Ext.define('MyApp.model.EOrder.Model.TestRequest', {
        extend : 'Ext.data.Model',
        fields : [{
                name : 'testId',
                type : 'int'
            }, {
                name : 'testCode'
            }, {
                name : 'testName'
            }, {
                name : 'price',
                type : 'float'
            }
        ]
    });
    
    var testStagingStore = Ext.create('Ext.data.Store', {
            model : 'MyApp.model.EOrder.Model.TestRequest',
            storeId : 'StagingTestRequest',
            autoLoad : false,
            proxy : {
                type : 'ajax',
                url : 'LOINC.json',
                reader : {
                    type : 'json',
                    root : 'TestRequest'
                }
            },
            listeners : {
                load : function () {
                    loadedCount = this.data.getCount();
                    console.log('json file loaded. processed records:' + loadedCount);
                }
            }
        });
    
    testStagingStore.load();
    
    console.log(testStagingStore.data.items);    // in chrome "network" console, I know my json file was loaded successfully. But here I get nothing!
    

    `

    不确定数据属性是否正确填充。

    我相信您也有同样的问题,因为getAt将从数据属性中检索记录。

        4
  •  -1
  •   Aashray    13 年前

    我想你需要提到 url 在代理内部,或者您需要使用 setProxy() 方法来设置URL。如果不这样做,则可能不会返回值。查看sencha文档了解更多信息。