简体   繁体   English

将数据从 json_encode PHP 推送到 javascript 数组中

[英]Push data into a javascript array from json_encode PHP

I am using a library that requires this kind of structure我正在使用需要这种结构的库

 var items = [
  new primitives.orgdiagram.ItemConfig({
    id: 0,
    parent: null,
    title: "Scott Aasrud",
    description: "Root",
    phone: "1 (416) 001-4567",
    email: "scott.aasrud@mail.com",
    image: "demo/images/photos/a.png",
    itemTitleColor: primitives.common.Colors.RoyalBlue
  }),
  new primitives.orgdiagram.ItemConfig({
    id: 1,
    parent: 0,
    title: "Ted Lucas",
    description: "Left",
    phone: "1 (416) 002-4567",
    email: "ted.lucas@mail.com",
    image: "demo/images/photos/b.png",
    itemTitleColor: primitives.common.Colors.RoyalBlue
  }),
];

options.items = items;

How can I push data retrieved from my PHP json to the array?如何将从我的 PHP json 检索到的数据推送到数组? The one that confuses me is the让我困惑的是

new primitives.orgdiagram.ItemConfig

The json that is retrieved from my PHP is this part从我的 PHP 中检索到的 json 是这部分

id: 0,
parent: null,
title: "Scott Aasrud",
description: "Root",
phone: "1 (416) 001-4567",
email: "scott.aasrud@mail.com",
image: "demo/images/photos/a.png",
itemTitleColor: primitives.common.Colors.RoyalBlue

can somebody help me please??有人可以帮我吗??

thank you :)谢谢你 :)

Try below code.试试下面的代码。 In case JSON has multiple objects use a for loop to push the values into the array.如果 JSON 有多个对象,请使用 for 循环将值推送到数组中。

var items = [];

var item1 = new primitives.orgdiagram.ItemConfig({
  id: 0,
  parent: null,
  title: "Scott Aasrud",
  description: "Root",
  phone: "1 (416) 001-4567",
  email: "scott.aasrud@mail.com",
  image: "demo/images/photos/a.png",
  itemTitleColor: primitives.common.Colors.RoyalBlue
});

items.push(item1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM