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

查看:13
本文介绍了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 告诉我 missing ;before 语句在 ext-all.js 中返回 obj.cn.0(第 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 文档 关于 JSON 应该是什么样子.

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 配置选项是必需的,您不能将其留空.在上面的示例中,您的 root 将是行".

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

在将其提供给 JSONReader 之前,您可能首先需要将您的 JSON 解析为更简单的格式.

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天全站免登陆