문제

노드가있는 트리 구조를 보여주는 xsltlistviewwebpart가 있습니다. Postbacks간에 노드 (확장 / 축소)의 상태를 유지하는 쿠키를 설정하는 jQuery 스크립트를 만들었습니다.

스크립트를 다음과 함께 추가했습니다.

_spBodyOnLoadFunctionNames.push("RestoreClickedState");
.

... 스크립트가 페이지에서 마지막으로 실행되도록하십시오.

문제가 일관성없는 결과를 얻는 것입니다.

포스트 백과 내 스크립트는 노드를 닫는 것입니다. 예를 들어 노드를 확장하고 9 개의 닫힘을 닫은 후 9 개의 노드가 닫히지 만 확장 된 내 확장은 닫히고 나는 닫히고 나는 그림을 닫는 것 같습니다. 왜 그런지.

다른 노드의 경우, 노드를 확장하고 다른 노드가 누적 된 후에 다른 노드가 올바른 대신 잘못 확장되는 경우가 있습니다.

여기 내 스크립트가 있습니다 :

<script>
$(window).unload(function()
{  
RememberClickedState();
});


var items = '';
function RememberClickedState() {
$('.ms-listviewtable tbody[id^="tbod"]').each(function(){
    tid = $(this).attr('id');
    tvisible = ($(this).attr('style') == undefined ||
       $(this).attr('style').indexOf('display: none;') == -1);
    items += tid+':'+tvisible+','
})
$.cookie("itemListState", items);
}
function RestoreClickedState() {
//alert("beginne");
string = $.cookie("itemListState");
//alert(string);
var cookies = string.split(',');
//alert(cookies.length);
$.each(cookies, function(i, val){
    val = val.split(':');
    show = (val[1] == 'true' ? true:false);
    var test = val[0].substring(val[0].length -1, 1);
    var thisID = test.replace("bod", "");  
    var thisImgID = "img_" + thisID;
    if(!show && thisID)
    {
        //alert(thisID + " - " + thisImgID + " hiding");
        ExpCollGroup(thisID, thisImgID);// ,null, show); 
    }       
}); 

//$.cookie("itemListState", null);

} 

_spBodyOnLoadFunctionNames.push("RestoreClickedState");

</script>
.

경고를 사용하여 각 포스트 백 후에 쿠키의 내용을 확인하면 모든 쿠키를 올바르게 표시하므로 스크립트의 쿠키 부분이 작동하지만 쿠키에 따른 확장 / 축소가 아닙니다.

는 지금 약 4 일 동안 이것을 다루고 있기 때문에 어떤 아이디어를 가지고 있습니다.

미리 감사드립니다.

최고의 안부, Andrei

편집은 모든 것이 작동하지만 두 번째 포스트 백을 위해 모든 일이 일어나는 것을 실현했습니다. 따라서 쿠키가 생성 된 후 첫 번째 포스트 백은 쿠키에서 노드가 올바르게 읽혀 지지만 잘못 확장 / 축소되었지만 포스트 백에서 노드가 올바르게 확장 / 축소됩니다. _spBodyOnloadFunctionNames.push에 문제가 있음을 어떻게 믿는 것을 믿게합니다.

다른 이벤트 $ (윈도우) .unload가 올바르게 읽혀 지므로 첫 번째 이벤트가 예상대로 작동하므로 문제가 될 수 없습니다.


편집 30.07.2012 :

TreeView에 대해 더 명확하게하려고 노력할 것입니다. "TreeView"로 구성 요소 자체는 WebPartPages입니다. xsltlistviewwebpart, yes 이것은 그룹화 옵션이있는 표준보기입니다. 추가 정보가 필요한 경우 알려주십시오.

도움이 되었습니까?

해결책

Assuming that you used the default grouping options available in SharePoint lists: SharePoint already has this memorization behavior built in, and you are duplicating it.

Here is what could possibly happen:

  • when the page loads, SharePoint expands the node because this is the stored state
  • your script does the same interpretation and collapses it back

Here is what you could try:

  • remove your script and see if the default behavior is just what you need
  • instead of a script that switches states (ExpCollGroup), write a script that explicitly sets the state to expanded or collapsed. This way there is no risk of double switching.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top