0

我有很多人,每个人都有一系列联系人。数据为json格式:

[
  {
    "id": 7900,
    "position": "Tillitsvalgt",
    "person": {
      "id": 1000001,
      "lastName": "Andrushko",
      "contacts": [
        {
          "id": 1000001,
          "personId": 1000001,
          "type": {
            "id": 5,
            "name": "Mobile phone"
          },
          "value": "25417"
        },
        {
          "id": 1000002,
          "personId": 1000001,
          "type": {
            "id": 35,
            "name": "Mobile phone"
          },
          "value": "945417"
        }
      ]
    }
  },
  {
    "id": 7900,
    "position": "Tillitsvalgt",
    "person": {
      "id": 1000001,
      "lastName": "Andrushko",
      "contacts": [
        {
          "id": 1000001,
          "personId": 1000001,
          "type": {
            "id": 5,
            "name": "Mobile phone"
          },
          "value": "25417"
        },
        {
          "id": 1000002,
          "personId": 1000001,
          "type": {
            "id": 35,
            "name": "Mobile phone"
          },
          "value": "945417"
        }
      ]
    }
  }
]

我想显示两个网格,第一个带有人员,第二个带有所选人员的联系人。我创建了两个模型:

Ext.define('Person', {
    extend: 'Ext.data.Model',

    fields: [
        {
            mapping: 'person.lastName',
            name: 'lastName'
        }
    ],

    hasMany: [
        {
            associationKey: 'person.contacts',
            model: 'Contact',
            name: 'contacts'
        }
    ],
    proxy: {
        type: 'ajax',
        url: 'MemberServlet?operation=get',
        reader: {
            type: 'json'
        }
    }
});

和联系人模型:

Ext.define('Contact', {
    extend: 'Ext.data.Model',

    fields: [
        {
            mapping: 'type.name',
            name: 'type'
        },
        {
            name: 'value'
        }
    ],

    belongsTo: {
        model: 'Person'
    }
});

在这样的配置中,我的第二个网格显示所有人的联系人,我希望它只显示给选定的人。我该怎么做?

4

0 回答 0