首页 > 多维input name嵌套问题

多维input name嵌套问题

我碰上了几乎和下面这个同样的问题:

http://stackoverflow.com/questions/13305417/multidimensional-form-arra...

上面提到的所有答案,包括使用 formToObject库的方法全部无效。

是希望能一个form,不维护name中的数组下标的前提下,输出类似这样的结果:

js{
    statistics: [
        {
            title: 'aaaa',
            spiders: [
                {
                    like: 'engine',
                    url: 'baidu.com'
                },
                {
                    like: 'engine',
                    url: 'google.com'
                }
            ]
        },
        {
            title: 'bbbb'
        }
    ]
}

目前尝试的方案:

html<input type="text" name="statistics[][title]">
<input type="text" name="statistics[][spiders[][like]]">
<input type="text" name="statistics[][spiders[][url]]">

完全不行,求解脱……


貌似Stackoverflow已经解决这个问题了啊。
先全部取出来,放到数组里面,然后遍历重新生成新格式的JSON啊。

【热门文章】
【热门文章】