Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Fix the problem with set_id function in jsTree

So i'm trying to make jsTree from sql database via php. I have seen a lot of examples, and what i have got at this moment. This is my php code:

case 'create_node':
   $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int)$_GET['id'] : 0;
   $nodeText = isset($_GET['text']) && $_GET['text'] !== '' ? $_GET['text'] : '';
   $statement = $pdo->prepare("INSERT INTO table(id, name, text, parent_id) VALUES (DEFAULT, ?, ?, ?)");
   $statement->execute(array($nodeText, $nodeText, $node));
   $last_id = $statement->fetchColumn(); //use because PostgreSQL 
   $result = array('id' => $last_id);
   break;
echo json_encode($result); // output is {id:23} etc

And this is part of JS code:

$(document).ready(function () {
$('#tree-container').jstree({
    'plugins': ['contextmenu', 'dnd', 'wholerow'],
    'core': {
        'data': {
            'url': 'response.php?operation=get_node',
            'data': function (node) {
                return {
                    'id': node.id
                };
            },
            "dataType" : "json"
        },
        'check_callback': true,
        'themes': {
            'responsive': false
        }
    }
}).on('create_node.jstree', function (e, data) {
    $.get('response.php?operation=create_node', {
            'id': data.node.parent,
            'position': data.position,
            'text': data.node.text
        })
        .done(function (d) {
            data.instance.set_id(data.node, d.id);
        })
        .fail(function () {
            data.instance.refresh();
        });

So in the end of operation i will have this error message: TypeError: id is undefined (in set_id function parameter in jstree.js)

My tree is working but after adding new node i need to refresh page to edit text in this node (i want create and rename with one operation like in example on library site). Thanks for helping...

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda