在json2html上从child访问父对象属性

时间:2013-11-24 18:27:14

标签: javascript jquery arrays json json2html

我正在使用json2html.js将json数据解析成html,我在尝试访问子数组的父属性时遇到了问题,我知道这可能不可能但是可能你可以启发我如何做它,下面的例子是JSON字符串和json2html转换......

{         “日期”:“2013-11-18”,             “cityid”:“2”,             “timeframe”:“2”,             “时隙”: [{             “时间”:“07:00:00”,                 “有用”:1         },{             “时间”:“17:00:00”,                 “有效”:0         }] }

我们使用2个不同的转换字符串1来渲染顶部(date,cityid,timeframe),另一个渲染内部部分(timeslots)问题是我们需要从顶部部分访问数据,例如timeframe属性或下面的timeslots数组转换中的对象数组索引是我们用来呈现的两个转换:

var stimes = {
    "tag": "li",
        "children": [{
        "tag": "input",
            "type": "radio",
            "id": function (obj, index) {
            return (index);
        },
            "value": "${time}",
            "name": "btn",
            "html": ""
    }, {
        "tag": "label",
            "for": "0_1",
            "html": function (obj) {
            return (fixFrame(obj.time, 2));
        }
    }]
};

var daysheader = {
    "tag": "div",
        "id": function (obj, index) {
        return ("day_" + index)
    },
        "class": "daycol",
        "children": [{
        "tag": "ul",
            "children": [{
            "tag": "li",
                "children": [{
                "tag": "h3",
                    "html": function (obj) {
                    return (formatDay(obj.date, "dddd"))
                }
            }, {
                "tag": "p",
                    "class": "dat",
                    "html": function (obj) {
                    return (formatDay(obj.date, "mmm dS"))
                }
            }]
        }, {
            tag: "p",
            children: function (obj) {
                return (json2html.transform(obj.timeslots, stimes));
            }
        }]
    }]
};

我们还需要父数组索引为每个无线电输入生成不同的id,这里是测试的链接... http://jsfiddle.net/viktorq/wRT74/

0 个答案:

没有答案