2017-12-18 139 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