如何配置 extjs 阅读器来读取这个 json? [英] how to configure extjs reader to read this json?

查看:20
本文介绍了如何配置 extjs 阅读器来读取这个 json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了 extjs store 来从 useragentstring.com api 加载数据,这个 api 返回这样的数据

I've configured extjs store to load data from useragentstring.com api, this api return data like this

{"agent_type":"Browser","agent_name":"Opera","agent_version":"9.70","os_type":"Linux","os_name":"Linux","os_versionName":"","os_versionNumber":"","os_producer":"","os_producerURL":"","linux_distibution":"Null","agent_language":"English - United States","agent_languageTag":"en-us"}

Ext.define('Oms.model.Userinfo', {
    extend  : 'Ext.data.Model',
    fields  : ['agent_type', 'agent_name', 'agent_version', 'os_type', 'os_name']
});

Ext.define('Oms.store.Userinfo', {
    extend      : 'Ext.data.Store',
    model       : 'Oms.model.Userinfo',
    proxy: {
        type    : 'jsonp',
        reader  : {
            type: 'json',
            root: ''
        }       
    }
});

这家商店抛出一个错误

这可能是因为这个 json 中没有 root 吗?

maybe this happen because there is no root in this json ?

知道如何正确读取此输出并加载存储吗?

any idea how to read this output and load store correctly?

问候

推荐答案

当我未设置 root 或将其设置为 undefined 时,它对我有用.

It works for me when I don't set root or when I set it to undefined.

您还可以扩展 Ext.data.reader.Json 以调整对您的需求的响应.示例:

You may also extend Ext.data.reader.Json to adjust response to your needs. Example:

Ext.define('Ext.data.reader.JsonPWithoutRoot', {
    extend: 'Ext.data.reader.Json',
    read: function(response) {
        return this.callParent([ { root: response } ]);
    },
    root: 'root'
});

然后在代理中像这样定义它:

And then in proxy define it like this:

proxy: {
    type: 'jsonp',
    callbackKey: 'method',
    url: 'http://localhost/ext4/data3.php',
    reader: Ext.create('Ext.data.reader.JsonPWithoutRoot', {})
}

这篇关于如何配置 extjs 阅读器来读取这个 json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆