extJS:读取嵌套JSON [英] extJS: reading a nested JSON

查看:313
本文介绍了extJS:读取嵌套JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自ldap_search()调用的漂亮的嵌套JSON。我想使用这些信息来填充ExtJS ComboBox,但我面临一些读者的麻烦。显然,我无法读取ComboBox中需要的信息,即人员,uid和cn的邮件地址

I have a pretty nested JSON coming from a ldap_search() call. I would like to use this information to populate an ExtJS ComboBox, but I am facing some troubles with the reader. Apparently, I am not able to read the information that I need in the ComboBox, that is the mail address of the people, the uid and the cn

我认为整个问题在于商店。我尝试下面的代码:

I think the whole problem lies in the store. I was trying the following code:

var store= new Ext.data.JsonStore({
        url:'search.php',   
        root: '',
        totalProperty: 'count',
        fields: [
            {name:'cn', type: 'string', mapping:'cn.0'},
            {name:'mail', type: 'string', mapping:'mail.0'},
            {name:'uid', type: 'string', mapping:'uid.0'}
        ]
});

但FireBug告诉我 before语句返回obj.cn.0在ext-all.js(第7行)。我尝试了另一个更容易的JSON数组,它的工作原理,这就是为什么我真的认为问题在于这部分代码,特别是在映射。

but FireBug told me missing ; before statement return obj.cn.0 in ext-all.js (line 7). I tried with another, easier JSON array and it works, that is why I really think the problem lies in this part of code, especially in the mapping.

一个例子search.php返回的JSON为:

an example of JSON returned by search.php is:

{
  "count": 2,
  "0": {
    "mail": {
      "count": 1,
      "0": "Mail address not registered."
    },
    "0": "mail",
    "uid": {
      "count": 1,
      "0": "name0.surname0@domain.com"
    },
    "1": "uid",
    "cn": {
      "count": 1,
      "0": "Surname0 Name0"
    },
    "2": "cn",
    "count": 3,
    "dn": "cn=Surname0 Name0,ou=personal,dc=domain,dc=com"
  },
  "1": {
    "mail": {
      "count": 1,
      "0": "name1.surname1@domain.com"
    },
    "0": "mail",
    "uid": {
      "count": 1,
      "0": "name1.surname1"
    },
    "1": "uid",
    "cn": {
      "count": 1,
      "0": "Surname 1 Name 1"
    },
    "2": "cn",
    "count": 3,
    "dn": "cn=Surname1 Name1,ou=personal,dc=domain,dc=com"
  }
}

谢谢您的时间。

推荐答案

是的,JSON结构不能立即使用标准ExtJS JSONReader 。请查看此示例,该示例取自 ExtJS API文档

Yep, that JSON structure is not going to work straight away with standard ExtJS JSONReader. Take a look at this example taken from the ExtJS API documentation on how the JSON should look like.

{
    results: 2000, // Reader's configured totalProperty
    rows: [        // Reader's configured root
        // record data objects:
        { id: 1, firstname: 'Bill', occupation: 'Gardener' },
        { id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
        ...
    ]
}

此外,还需要 root config选项,不能将其留空。在上面的例子中,你的 root 将是rows。

Also, the root config option is required, you cannot leave it empty. In the above example your root would be "rows".

你可能需要解析JSON首先将它们转换为更简单的格式,然后将其送入JSONReader。

You are probably going to need to parse that JSON of yours into a simpler format at first, before feeding it to the JSONReader.

这篇关于extJS:读取嵌套JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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