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.