jsTree – načtení json dat z presenteru

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Juve
Člen | 27
+
0
-

Ahoj,
potřeboval bych načíst při inicializaci jstree stromu data z presenteru, nevím ale jak tento kod přepsat v rámci nette aplikace:

<script>
"json_data" : {
    // This tree is ajax enabled - as this is most common, and maybe a bit more complex
    // All the options are almost the same as jQuery's AJAX (read the docs)
    "ajax" : {
        // the URL to fetch the data
        "url" : "./server.php",
        // the `data` function is executed in the instance's scope
        // the parameter n is the node being loaded
        // (may be -1, 0, or undefined when loading the root nodes)
        "data" : function (n) {
            // the result is fed to the AJAX request `data` option
            return {
                    "operation" : "get_children",
                    "id" : n.attr ? n.attr("id").replace("node_","") : 1
            };
        }
    }
}
</script>

je mi jasné, že řádek „url“ : „./server.php“ určuje soubor, z kterého data budou čerpána a function(n) zase předává souboru server.php v poli $_REQUEST parametry „operation“ a „id“, jak to mam ale přepsat, pokud chci aby byly parametry předány nějaké metodě presenteru a ten nasledne ajaxově odpověděl a odeslal data?

Děkuji za pomoc

Felix
Nette Core | 1190
+
0
-

Zkus si treba metodu

public function handleTree($operation, $id) {
// vystup JSON
// napr:
$this->sendResponse(new JsonResponse(array('klic' => 'hodnota', ...)));
}

Url pak bude, example.com?do=tree&operation=asdasd&id=1231

Editoval Felix (27. 3. 2012 12:27)

Juve
Člen | 27
+
0
-

Díky, ale ještě nevím jak předat presenteru ty dva parametry..
konkretně:

<script>
"id" : n.attr ? n.attr("id").replace("node_","") : 1
</script>

..když se jedná o javascriptovou promennou..