Uso de Jstree

36 views
Skip to first unread message

isi_jca

unread,
Nov 17, 2015, 3:13:34 PM11/17/15
to web2py-usuarios
Hola comunidad!!!,

Tengo la siguiente función:

def prueba():
    lista=[]
    rows = db(db.tcbplancuenta).select()
    for j in rows:
        dic = {'text':j.descripcion,'id':j.nodo,'parent':j.padre}
        lista.append(dic)
    return locals()

Que retorna los siguientes datos:

[{'text': 'Plan de Cuenta Singh', 'id': '0', 'parent': '#'}, {'text': 'Activo', 'id': '1', 'parent': '0'}, {'text': 'Pasivo', 'id': '2', 'parent': '0'}, {'text': 'Patrimonio Neto', 'id': '3', 'parent': '0'}, {'text': 'Ingresos', 'id': '4', 'parent': '0'}, {'text': 'Egresos', 'id': '5', 'parent': '0'}, {'text': 'Activo Corriente', 'id': '11', 'parent': '1'}, {'text': 'Disponibilidades', 'id': '111', 'parent': '11'}, {'text': 'Caja', 'id': '1111', 'parent': '111'}, {'text': 'Fondo Fijo', 'id': '1112', 'parent': '111'}, {'text': 'Pasivo Corriente', 'id': '21', 'parent': '2'}, {'text': 'Deudores Comerciales', 'id': '211', 'parent': '21'}, {'text': 'Proveedores', 'id': '212', 'parent': '21'}]

Y tengo la siguiente vista:

{{extend 'layout.html'}}
<h3>Prueba de Árbol</h3>
<hr>
<link rel="stylesheet" href="{{=URL('static','css/jstree/style.min.css')}}"/>

<div id="plancuenta" class="demo"></div>

<script src="{{=URL('static','js/jquery.min.js')}}"></script>
<script src="{{=URL('static','js/jstree.min.js')}}"></script>

<script>
    $('#plancuenta').jstree({ 'core' :
       {'data': "{{=XML(lista)}}" }});
</script>

¿Cómo hago para pasar los datos a la función jstree?.

Asi mismo transcribo la misma función con código duro.

<script>
    $('#plancuenta').jstree({ 'core' :
       {'data': [{'text': 'Plan de Cuenta Singh', 'id': '0', 'parent': '#'}, {'text': 'Activo', 'id': '1', 'parent': '0'}, {'text': 'Pasivo', 'id': '2', 'parent': '0'}, {'text': 'Patrimonio Neto', 'id': '3', 'parent': '0'}, {'text': 'Ingresos', 'id': '4', 'parent': '0'}, {'text': 'Egresos', 'id': '5', 'parent': '0'}, {'text': 'Activo Corriente', 'id': '11', 'parent': '1'}, {'text': 'Disponibilidades', 'id': '111', 'parent': '11'}, {'text': 'Caja', 'id': '1111', 'parent': '111'}, {'text': 'Fondo Fijo', 'id': '1112', 'parent': '111'}, {'text': 'Pasivo Corriente', 'id': '21', 'parent': '2'}, {'text': 'Deudores Comerciales', 'id': '211', 'parent': '21'}, {'text': 'Proveedores', 'id': '212', 'parent': '21'}]
              }});

Saludos cordiales.

Federico Ferraro

unread,
Nov 17, 2015, 3:27:40 PM11/17/15
to web2py-...@googlegroups.com
Usando el debugger del navegador , que datos tenes en la función ?? 
A lo mejor es un problema con las " . 
<script>
    $('#plancuenta').jstree({ 'core' : 
       {'data': {{=XML(lista)}} }});
</script>

Slds ... 

--
Has recibido este mensaje porque estás suscrito al grupo "web2py-usuarios" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a web2py-usuari...@googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.



--
--
Federico Ferraro
Usuario Linux : 482533.
--

isi_jca

unread,
Nov 17, 2015, 3:42:09 PM11/17/15
to web2py-usuarios
Federico:

Muchas gracias!!!, por responder, efectivamente no lleva comillas. Ahora funciona de 10.

Saludos.
Reply all
Reply to author
Forward
0 new messages