2 yueyongxiang Yueyongxiang 于 2017.09.05 09:38 提问

关于数组里面传对象的问题

items: [{
                    title: "north panel",
                    html: "上",
                    region: "north",
                    height: 50
                }, {
                    title: "south panel",
                    html: "下",
                    region: "south",
                    height: 50
                }, {
                    title: "west panel",
                    html: "左",
                    region: "west",
                    width:100
                }, {
                    title: "east panel",
                    html: "右",
                    region: "east",
                    width: 100
                }, {
                    title: "center panel",
                    html: "中",
                    region: "center"
                }]

想写成这个样子,应该怎么写js文件呢?

6个回答

qq_29594393
qq_29594393   Ds   Rxr 2017.09.05 09:46

表示不懂你要表述什么?
提问要素:
想要达到的目的,
简述遇到的问题,
已经尝试过的解决方案

qq_38494537
qq_38494537   2017.09.05 09:44

你是想要json对象么?不如在java代码写个实体类,用list装这个实体类,然后通过Gson自动转换为Json对象传到页面

Small_Mouse0
Small_Mouse0   Ds   Rxr 2017.09.05 10:08

哎,,,题主这个话确实没说完,,,

提供一下参考资料,,(对象也同理)

 //数组转json串
var arr = [1,2,3, { a : 1 } ];
JSON.stringify( arr );

//json字符串转数组
var jsonStr = '[1,2,3,{"a":1}]';
JSON.parse( jsonStr );


qq_33727653
qq_33727653   2017.09.05 10:55
 var items= [{
                    title: "north panel",
                    html: "上",
                    region: "north",
                    height: 50
                }, {
                    title: "south panel",
                    html: "下",
                    region: "south",
                    height: 50
                }, {
                    title: "west panel",
                    html: "左",
                    region: "west",
                    width:100
                }, {
                    title: "east panel",
                    html: "右",
                    region: "east",
                    width: 100
                }, {
                    title: "center panel",
                    html: "中",
                    region: "center"
                }]

楼主是要这样一个对象? 直接写不就完了? 感觉没理解楼主的意思!

Beamon__
Beamon__   2017.09.05 14:35

图片说明
图片说明
楼主可以创建一个数组,在创建数个对象,然后将对象添加至数组内

sunny_desmond
sunny_desmond   2017.09.06 15:38

LZ可以参考一下楼上的~

Csdn user default icon
上传中...
上传图片
插入图片