Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/07/2014, 05:52
Xmarq
 
Fecha de Ingreso: junio-2014
Mensajes: 9
Antigüedad: 9 años, 10 meses
Puntos: 0
Respuesta: Creacion dinamica de objeto JSON

Os dejo tambien mi objeto JSON inicializado a 0 (es decir sin seleccion de horarios y sin user)

Código HTML:
    var ch1: boolean = $("#check1").is(":checked");
    var ch2: boolean = $("#check2").is(":checked");
    var ch3: boolean = $("#check3").is(":checked");
    var ch4: boolean = $("#check4").is(":checked");
    var ch5: boolean = $("#check5").is(":checked");

    var jsonobj = '{"Data": {"User":"User","Data1": "08:00-10:00","Data2": "10:00-12:00", "Data3": "13:00-15:00", "Data4": "15:00-17:00", "Data5": "17:00-19:00"}, "Schedule": {"user": "", "sel1": 0, "sel2": 0, "sel3": 0, "sel4": 0, "sel5": 0 }}';


 var json = JSON.parse(jsonobj);


document.getElementById('json').innerHTML =
        "<table>" +
        "<tr>"
        + "<th>" + json.Data.User + "</th>"
        + "<th>" + json.Data.Data1 + "</th>"
        + "<th>" + json.Data.Data2 + "</th>"
        + "<th>" + json.Data.Data3 + "</th>"
        + "<th>" + json.Data.Data4 + "</th>"
        + "<th>" + json.Data.Data5 + "</th>"
        + "</tr>"
        + "<tr>"
        + "<th>" + json.Schedule.user + "</th>"
        + "<th>" + json.Schedule.sel1 + "</th>"
        + "<th>" + json.Schedule.sel2 + "</th>"
        + "<th>" + json.Schedule.sel3 + "</th>"
        + "<th>" + json.Schedule.sel4 + "</th>"
        + "<th>" + json.Schedule.sel5 + "</th>"
        + "</tr>"
        + "</table>";

Con esto quiero crear una tabla con los datos recuperados del objeto json creado. asi si funciona pero lo que quiero es sustituir los sel1 , sel2 etc que en un principio estan inicializados a 0 por el valor de las variables ch1, ch2 etc y asi crear el json de forma dinamica