0

我有以下数组:

var phyList = [
    {
    "firstName": "Michael",
    "lastName": "Abbey-Mensah",
    "status": "Courtesy",
    "specialty": "Pediatrics",
    "address": "4564454, Brooklyn, NY 11212",
    "phone": "718 || 718.385.9279"
    },
    {
    "firstName": "Niraj",
    "lastName": "Acharya",
    "status": "Active",
    "specialty": "Medicine",
    "address": "4545 Avenue, Jamaica NY 11432",
    "phone": "4545.558.2894 || 4545.558.9735"
    }
];

如果我想在第一个条目中拥有多个专业怎么办?比方说儿科外科

这会起作用吗:

var phyList = [
    {
    "firstName": "Michael",
    "lastName": "Abbey-Mensah",
    "status": "Courtesy",
    "specialty": ["Pediatrics", "Surgery"],
    "address": "454545ergaston Blvd, Brooklyn, NY 11212",
    "phone": "745458.485.2704 || 516.385.9279"
    },
    {
    "firstName": "Niraj",
    "lastName": "Acharya",
    "status": "Active",
    "specialty": "Medicine",
    "address": "45459th Avenue, Jamaica NY 11432",
    "phone": "718.558.2894 || 718.558.9735"
    }
];
4

3 回答 3

2

您可以在数组中维护特殊值:

var phyList = [
    {
    "firstName": "Michael",
    "lastName": "Abbey-Mensah",
    "status": "Courtesy",
    "specialty": ["Pediatrics ","Surgery"],
    "address": "437 Mothergaston Blvd, Brooklyn, NY 11212",
    "phone": "718.485.2704 || 516.385.9279"
    },
    {
    "firstName": "Niraj",
    "lastName": "Acharya",
    "status": "Active",
    "specialty": ["Medicine"],
    "address": "152-11 89th Avenue, Jamaica NY 11432",
    "phone": "718.558.2894 || 718.558.9735"
    }
];
于 2013-04-30T12:11:08.440 回答
1

我想,你需要有一个这样的数组

var a = [{"id":"1","images":[{"img_id":"1"},{"img_id":"2"},{"img_id":"3"}]},
     {"id":"2","images":[{"img_id":"1"},{"img_id":"2"},{"img_id":"3"}]}];

其中,Images 的条目有一个值数组

于 2013-04-30T12:09:59.177 回答
1

您可以使用

     "specialty": [
         "Pediatrics", "Surgery"
     ],     

一个数组可以在一个名称下保存许多值,您可以通过引用索引号来访问这些值。

于 2013-04-30T12:10:55.150 回答