2017-12-18 135 views
0

我已經嘗試了很多。在頁面加載正常工作。無法傳遞參數來加載JSTree(重新渲染)

我想在DataTable行點擊重新加載JStree。從DataTable行取Id並將其傳遞給JStree。 每當我把JSTree放入一個函數。它不在頁面上呈現。 我嘗試了不同的方法。但沒有成功。只處理頁面加載。

的DataTable

$('#roles').on('click', 'tr', function() { 
    var id = table.row(this).id(); 
    alert(id); 
    id = table.row(this).id(); 

    $.ajax({ 
     async: true, 
     type: "POST", 
     url: '/Home/GetData', 
     dataType: "json", 
     data: { roleId: id }, 
     success: function (json) { 
      createJSTree(json); 
     }, 
     error: function (xhr, ajaxOptions, thrownError) { 
      alert(xhr.status); 
      alert(thrownError); 
     } 
    }); 
}); 

JSTree

function createJSTree(jsondata) { 
    $('#app_tree').jstree({ 
     'core': { 
      'data': jsondata 
     } 
    }); 
} 

在頁面加載

$('#app_tree').jstree({ 
    'plugins': ["wholerow", "checkbox", "types"], 
    'core': { 
     "themes": { 
      "responsive": false 
     } 
    } 
}); 

這是在頁面加載

$('#app_tree').jstree({ 
    'plugins': ["wholerow", "checkbox", "types"], 
    'core': { 
     'check_callback': true, 
     "themes": { 
      "responsive": false 
     }, 
     'data': { 
      'type': "POST", 
      "url": function (node) { 
       return "/Home/GetData?roleId=acb31181-b364-4a57-8806-70f5fcb07d1f"; 
      }, 
      'contentType': "application/json" 
     } 
    } 
}); 

回答

0

做工精細,你可能需要重新繪製JSTree爲您的新數據。

請檢查堆棧類似here

+0

重繪沒有工作:( – Ali