在数组JQuery中有一个数组

时间:2013-04-30 12:06:39

标签: javascript

我有以下数组:

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"
    }
];

3 个答案:

答案 0 :(得分: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"
    }
];

答案 1 :(得分: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具有其条目的值数组

答案 2 :(得分:1)

您可以使用

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

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