【问题标题】:Store's metadata won't load商店的元数据不会加载
【发布时间】:2011-09-01 04:07:26
【问题描述】:

我尝试通过元数据将字段配置加载到 json 存储。 json是:

{
   "rows":[
      {
         "datev":"02.01.2011",
         "w1":"100",
         "w2":"200"
      },
      {
         "datev":"02.01.2011",
         "w1":"300",
         "w2":"50"
      },
      {
         "datev":"03.01.2011",
         "w1":"10",
         "w2":"450"
      }
   ],
   "metaData":{
      "fields":[
         {
            "name":"datev"
         }
      ],
      "root":"rows"
   }
}

我的商店是:

var test = new Ext.data.JsonStore({
                  url: 'test.php'    
           });
test.load();

元数据未加载。代码有什么问题?

【问题讨论】:

    标签: json extjs store jsonstore


    【解决方案1】:

    您没有指定 Id 属性,也没有指定 Root 属性。这是我的代码,希望对您有所帮助

    var EStore = new Ext.data.JsonStore
        ({
          api: { read: 'getAssignedJobs',
                 create: 'createAssignedJobs',
                 update: 'updateAssignedJobs'
         },
         root: 'jobData',
         idProperty: 'Id',
         autoSave: true,
         batch: false,
         successProperty: 'success',
         writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }),
         fields: [
            { name: 'Id', type: 'int' },
            { name: 'ResourceId', mapping: 'fitter_id', type: 'int' },
            { name: 'StartDate', type: 'date', format: 'd/m/Y G:i' },
            { name: 'EndDate', type: 'date', format: 'd/m/Y G:i' },
            { name: 'status', type: 'int' },
            { name: 'job_id', type: 'int' }
         ]
    });
    

    【讨论】:

      【解决方案2】:

      我认为你需要添加一个 JSON 阅读器

      var reader = new Ext.data.JsonReader({
              fields: []
      });
      
      var store = new Ext.data.Store({
         nocache : true,
         reader : reader,
         autoLoad : true,
         remoteSort : true,
         proxy : new Ext.data.HttpProxy({
             url : '/getjson?queryable=featureType&featureType=Electronic%20Device',
             method : 'GET'
         })
      

      或许

      var store = new Ext.data.JsonStore({
          url: 'somewhere',
          fields: []
      });
      

      【讨论】:

      • 它没有帮助。我认为 JsonStore 没有属性“reader”
      • 我很确定你需要一个 JSONReader,因为它是理解元数据的对象dev.sencha.com/deploy/ext-3.3.1/docs/?class=Ext.data.JsonReader
      • 来自 api:“一个 JsonStore 将自动配置一个 Ext.data.JsonReader。”
      • 我以前遇到过这个,但我现在没有参考资料,所以想记住。我已经更新了我的示例......或者您可以添加字段:[] 到您的商店配置
      • 您是否 100% 确定您的服务器发送回正确的 JSON?是响应application/json的Content-Type吗?
      猜你喜欢
      • 2014-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多