在EXTJS中将JSON数据加载到组合框中时出现Reader Undefined错误

时间:2011-07-28 17:02:33

标签: json extjs

我有两个下拉列表,在更改一个下拉列表的值时,它应该在另一个下拉列表中填充值。我正在使用JSON进行ajax调用,我也得到了响应。但在得到响应之后,值没有被加载到第二个组合框的存储中。获取错误:读者未定义 以下是我的代码:

//第二个COMBO描述

  var AGENT_NAME_Field = Ext.create('Ext.form.field.ComboBox', {
    id: 'AGENT_NAME',
    name: 'AGENT_NAME',       
    width: 300,
    displayField: 'name',
    store: agentNameStore,
    queryMode: 'local',
    allowBlank: false,
    listConfig: {
        getInnerTpl: function() {
            return '<div data-qtip="{name}">{name}</div>';
        }
    }
}); 

//存储第二个组合

 var agentNameStore = Ext.create('Ext.data.Store', {
  proxy: {
    type: 'ajax',
    url : 'name.json',
    reader: new Ext.data.JsonReader({
        totalProperty: 'results',
        root:'items'
    }, [{name: 'name'}, {name: 'name'}])

}

}); 

//这是我进行ajax调用的方式,而FUNCTION_NAME_Field是第一个组合

 FUNCTION_NAME_Field.on('select', function() {
    AGENT_NAME_Field.reset();
    agentNameStore.proxy= new Ext.data.HttpProxy({url: '/omsWeb/navigation/getAgent.htm?id='+FUNCTION_NAME_Field.getValue()});
    agentNameStore.load();
});

我追踪了日志,我得到的回应是成功但是之后它的投掷错误:Reader undefined。 我错过了什么吗?或者是错的?有谁可以帮忙。 谢谢 普利文

2 个答案:

答案 0 :(得分:0)

试试这个:

  1. 删除此字符串:

    agentNameStore.proxy= new Ext.data.HttpProxy({url: '/omsWeb/navigation/getAgent.htm?id='+FUNCTION_NAME_Field.getValue()});
    
  2. 并替换商店代理中的url值:

    url: '/omsWeb/navigation/getAgent.htm?id='+ Ext.ComponentManager.get(ID).getValue()}
    
  3. 其中 ID 是FUNCTION_NAME_Field的ID

    <强>编辑:

    检查我为您创建的示例

    Ext.onReady(function() {
    
      var ds = Ext.create('Ext.data.Store', {
          pageSize: 10,
          proxy: {
            type: 'jsonp',
            url : 'http://www.sencha.com/forum/topics-remote.php',
            reader: {
              type: 'json',
              root: 'topics',
              totalProperty: 'totalCount'
            }
          },
    
          fields: [
            {name: 'id', mapping: 'post_id'},
            {name: 'title', mapping: 'topic_title'},
            {name: 'topicId', mapping: 'topic_id'},
            {name: 'author', mapping: 'author'},
            {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
            {name: 'excerpt', mapping: 'post_text'}
          ]
      });
    
      var ds2 = Ext.create('Ext.data.Store', {
          pageSize: 10,
          fields: [
            {name: 'id', mapping: 'id'},
          ]
      });
    
      var cb1 = Ext.create('Ext.form.ComboBox', {
          id: 'cb1',
          fieldLabel: 'TEST',
          store: ds,
          displayField: 'title',
          valueField: 'id',
          multiSelect: false,
          renderTo: Ext.getBody()
      });
    
      var cb2 = Ext.create('Ext.form.ComboBox', {
          disabled : true,
          id: 'cb2',
          fieldLabel: 'TEST2',
          store: ds2,
          displayField: 'title',
          valueField: 'id',
          renderTo: Ext.getBody()
      });
    
      cb1.on('select', function(combo, value) {
          cb2.enable();       
          ds2.load();     
      });
    
      ds2.on('beforeload', function(store, operation) {
          alert(Ext.ComponentManager.get('cb1').getValue());
          this.setProxy(Ext.create('Ext.data.proxy.Ajax', {
                url : '/omsWeb/navigation/getAgent.htm',
                extraParams : {
                    id: Ext.ComponentManager.get('cb1').getValue()
                }
              }));
      },ds2);
    })
    

答案 1 :(得分:0)

您正在重新定义代理,而不包含读者定义。不知道你为什么开始这样做 - 每个组合应该已经拥有自己的预配置商店+代理+阅读器。我不确定你为什么要在飞行中改变它。