jquery - Can not render dynatree treeview a second time when the containing div is cleared with $.empty() -


i rendering dynatree treeview in #treediv opentemplate function. before load units template in dynatree empty/clear #treediv remove existing tree. works first time.

when try load other units template in #treediv not see unit data, div empty. somehow #treediv got corrupted because code run first time creating unit tree. difference @ 2nd time .empty() there exist tree.

what wrong?

function opentemplate(dlg, form) {         $.ajax({             url: $(form).attr('action'),             type: 'post',                                  data: form.serialize(),             success: function (response) {                           if (response.success) {                     dlg.dialog("close");                                    $('#treediv').empty();                             loadunits(response.data);                                     }                 else {                     // reload dialog form show model/validation errors                      dlg.html(response);                 }             }         });     }   function loadunits(data) {                $('#treediv').dynatree({             onactivate: function (node) {                 getteststeps(node.data.key);             },                         onlazyread: function (node) {                            node.appendajax({                     url: '@url.action("getchildrenunits","unit")',                     data: {"unitid": node.data.key, "templateid": 1 }                 });             },             children: data         });     } 

it looks invocation of empty() not complete before loadunits invocation.

you wrap empty() call in untiltimeout. or encapsulate in in try, or if statment. ie, if empty finished call loadunits


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -