2013-07-08 5 views
0

MVC 4에서는 jstree를 사용합니다. 생성 작업에서 나는 문제가 없다. 하지만 편집 작업에서는 treemodel의 일부 항목에 true 값을 설정했습니다. 내가 트리 모델을 채울 때jstree에서 선택한 항목을로드시 검사로 만드는 방법. (selected = "selected"not working)

public class RecursiveObject 
{    
    public string data { get; set; } 
    public Int64 id { get; set; } 
    public FlatTreeAttribute attr { get; set; } 
    public List<RecursiveObject> children { get; set; } 
} 

public class FlatTreeAttribute 
{ 
    public string id; 
    public bool selected; 
} 

, 내가 일부 항목에 selected = true;을 설정하고보기에서 이것을 사용 :

json_data: { 
       "ajax": { 
        url: "@Url.Action("GetTreeData", "MyController")", 
        type: "POST", 
        dataType: "json", 
        contentType: "application/json charset=utf-8" 
       } 
      }, 

그러나보기에

는 모든 항목이 체크되어 모델이 같다. <li> 태그에 selected = "selected"이 표시되어 있지만 확인에 영향을주지 않습니다.

을 수동으로 확인하면, jstree-uncheckedjstree-checked 클래스로 변경됩니다. selected = "selected"이 작동하지 않는다는 의미입니다.

어떻게이 문제를 해결할 수 enter image description here ?

답변

1

내 질문에 대한 해결책을 찾았습니다.

.bind("loaded.jstree", function (event, data) { 
    $('li[selected=selected]').each(function() { 
     $(this).removeClass('jstree-unchecked').addClass('jstree-checked'); 
    }); 
});