Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.javascript > #4949

Re: not a function

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups de.comp.lang.javascript
Subject Re: not a function
Date 2018-04-29 01:30 +0200
Organization PointedEars Software (PES)
Message-ID <539875bf-65c8-5053-b515-7a6491782f61@PointedEars.de> (permalink)
References <pbppha$jg2$1@news.albasani.net> <5377515.lOV4Wx5bFT@PointedEars.de> <pbrqbl$7tr$1@news.albasani.net>

Show all headers | View raw


Jan Novak wrote:
> ich habe die Daten jetzt aus der Funktion ausgelagert:
> 
> $.ajax({
>       url: variable + '/include/fetch_doc_groups.php',
>       async: false
>     }).done(function(data) {
>       dataNeu = JSON.parse(data);
>     });
> 
> 
> und hier nutze ich diese dann so:
> 
> var initSelectableTree = function() {
>    return $('#treeview-selectable').treeview({
>      data: dataNeu,
> 
> so funktioniert es.

Aber nur *zufällig*, mit *schneller* Netzverbindung und *lokalem*,
*schnellen* Server.

Schau Dir bitte mein UML-Sequenzdiagramm noch einmal *genau* an:

Du hast lediglich das Problem *verlagert*, denn Deine globale Variable(?!)
“dataNeu” ist nicht notwendigerweise gesetzt, wenn initSelectableTree()
aufgerufen wird.  Denn der Server hat möglicherweise noch nicht geantwortet.

Richtig geht es so (wie Dir bereits vor einem Monat erklärt), und vor allem
*ohne* globale Variablen:

  $.ajax({
     url: … + '/include/fetch_doc_groups.php',
     async: false
  }).done(function (data) {
    var dataNeu = JSON.parse(data);

    $('#treeview-selectable').treeview({
       data: dataNeu,
       …
    });
  });

Du hättest also auch einfach den Bootstrap-Code nehmen und

  $.getJSON(… + '/include/fetch_doc_groups.php',
    function (data) {
      $('#treeview-selectable').treeview({
        data: data,
        […]
      });
    });

schreiben können.  Allenfalls wäre noch

  (function () {
    var treeView;

    $.getJSON(… + '/include/fetch_doc_groups.php',
      function (data) {
        treeView = $('#treeview-selectable').treeview({
          data: data,
          […]
        });
      });

     /* … treeView … */
   }();

sinnvoll, wenn Du die Referenz auf den TreeView später noch brauchst.


HTH

PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)   // Plone, register_function.js:16

Back to de.comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

not a function Jan Novak <repcom@gmail.com> - 2018-04-25 13:41 +0200
  Re: not a function Sascha Hüdepohl <news@juenger-der-himmlischen-teekanne.de> - 2018-04-25 17:49 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 07:39 +0200
  Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-25 21:04 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 07:55 +0200
      Re: not a function "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2018-04-28 19:50 +0200
      Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-29 01:14 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 08:07 +0200
      Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-29 01:30 +0200
        Re: not a function Jan Novak <repcom@gmail.com> - 2018-05-02 15:06 +0200
          Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-05 01:00 +0100

csiph-web