2011-08-24 3 views
0

TreePanel에 문제가 있습니다. TreeLoader를 사용하여 URL에서 데이터를 가져옵니다. 예제 트리는 내 패널에서 올바르게 렌더링되므로 문제는 사용자 지정 데이터에 있어야합니다. 파이썬 cgi를 통해 내 데이터를 얻습니다. 작성하는 문자열을 단계별로 작성합니다.EXT JS 3 TreePanel 문제 : 트리가 표시되지 않습니다.

var Tree = Ext.tree; 

var tree = new Tree.TreePanel({ 
    useArrows: true, 
    autoScroll: true, 
    animate: true, 
    enableDD: true, 
    containerScroll: true, 
    border: false, 
    // auto create TreeLoader 
    dataUrl: '../python/tree/get_tree', 

    root: { 
     nodeType: 'async', 
     text: '369', 
    } 
}); 

파이썬 CGI에 의해 기록 된 데이터는 다음과 같다 : 이것은 TreePanel 코드

[{ 
    id: 476, 
    text: 'memShared', 
    leaf: true 
},{ 
    id: 477, 
    text: 'icmpInParmProbs', 
    leaf: true 
},{ 
    id: 478, 
    text: 'memTotalFree', 
    leaf: true 
},{ 
    id: 479, 
    text: 'icmpOutEchos', 
    leaf: true 
},{ 
    id: 480, 
    text: 'memAvailReal', 
    leaf: true 
},{ 
    id: 481, 
    text: 'icmpInAddrMaskReps', 
    leaf: true 
},{ 
    id: 482, 
    text: 'icmpInRedirects', 
    leaf: true 
},{ 
    id: 483, 
    text: 'loadavg1', 
    leaf: true 
},{ 
    id: 484, 
    text: 'tcpCurrEsta', 
    leaf: true 
},{ 
    id: 485, 
    text: 'icmpInErrors', 
    leaf: true 
},{ 
    id: 486, 
    text: 'icmpInMsgs', 
    leaf: true 
},{ 
    id: 498, 
    text: 'icmpInTimeExcds', 
    leaf: true 
},{ 
    id: 499, 
    text: 'tcpActiveOpens', 
    leaf: true 
},{ 
    id: 500, 
    text: 'eCpuRawNice', 
    leaf: true 
},{ 
    id: 512, 
    text: 'icmpOutTimeExcds', 
    leaf: true 
},{ 
    id: 513, 
    text: 'icmpInEchos', 
    leaf: true 
},{ 
    id: 514, 
    text: 'memBuffe', 
    leaf: true 
},{ 
    id: 515, 
    text: 'icmpInSrcQuenchs', 
    leaf: true 
},{ 
    id: 516, 
    text: 'icmpOutErrors', 
    leaf: true 
},{ 
    id: 517, 
    text: 'tcpAttemptFails', 
    leaf: true 
},{ 
    id: 518, 
    text: 'icmpOutAddrMaskReps', 
    leaf: true 
},{ 
    id: 519, 
    text: 'tcpOutSegs', 
    leaf: true 
},{ 
    id: 520, 
    text: 'loadavg15', 
    leaf: true 
},{ 
    id: 521, 
    text: 'tcpRetransSegs', 
    leaf: true 
},{ 
    id: 522, 
    text: 'tcpEstabResets', 
    leaf: true 
},{ 
    id: 523, 
    text: 'icmpOutTimestamps', 
    leaf: true 
},{ 
    id: 524, 
    text: 'memTotalReal', 
    leaf: true 
},{ 
    id: 525, 
    text: 'icmpOutTimestmpReps', 
    leaf: true 
},{ 
    id: 526, 
    text: 'icmpOutDestUnreachs', 
    leaf: true 
},{ 
    id: 527, 
    text: 'tcpPassiveOpens', 
    leaf: true 
},{ 
    id: 528, 
    text: 'memTotalSwap', 
    leaf: true 
},{ 
    id: 529, 
    text: 'tcpInSegs', 
    leaf: true 
},{ 
    id: 530, 
    text: 'icmpOutSrcQuenchs', 
    leaf: true 
},{ 
    id: 531, 
    text: 'icmpInTimestampReps', 
    leaf: true 
},{ 
    id: 532, 
    text: 'icmpOutEchoReps', 
    leaf: true 
},{ 
    id: 533, 
    text: 'tcpOutRsts', 
    leaf: true 
},{ 
    id: 534, 
    text: 'icmpInAddrMasks', 
    leaf: true 
},{ 
    id: 535, 
    text: 'memSwapErro', 
    leaf: true 
},{ 
    id: 536, 
    text: 'eCpuRawIdle', 
    leaf: true 
},{ 
    id: 537, 
    text: 'eCpuRawKernel', 
    leaf: true 
},{ 
    id: 538, 
    text: 'memAvailSwap', 
    leaf: true 
},{ 
    id: 539, 
    text: 'tcpInErrors', 
    leaf: true 
},{ 
    id: 540, 
    text: 'icmpOutAddrMasks', 
    leaf: true 
},{ 
    id: 541, 
    text: 'icmpOutRedirects', 
    leaf: true 
},{ 
    id: 542, 
    text: 'eCpuRawSystem', 
    leaf: true 
},{ 
    id: 543, 
    text: 'eCpuRawInterrupt', 
    leaf: true 
},{ 
    id: 544, 
    text: 'icmpOutMsgs', 
    leaf: true 
},{ 
    id: 545, 
    text: 'icmpInTimestamps', 
    leaf: true 
},{ 
    id: 546, 
    text: 'icmpInEchoReps', 
    leaf: true 
},{ 
    id: 547, 
    text: 'eCpuRawWait', 
    leaf: true 
},{ 
    id: 548, 
    text: 'eCpuRawUse', 
    leaf: true 
},{ 
    id: 549, 
    text: 'memCached', 
    leaf: true 
},{ 
    id: 550, 
    text: 'loadavg5', 
    leaf: true 
},{ 
    id: 551, 
    text: 'icmpInDestUnreachs', 
    leaf: true 
},{ 
    id: 552, 
    text: 'icmpOutParmProbs', 
    leaf: true 
},{ 
id: 501, 
text: e, 
children: [{ 
    id: 502, 
    text: 'ifInOctets', 
    leaf: true 
},{ 
    id: 503, 
    text: 'ifOutUcastPkts', 
    leaf: true 
},{ 
    id: 504, 
    text: 'ifOutNUcastPkts', 
    leaf: true 
},{ 
    id: 505, 
    text: 'ifInDiscards', 
    leaf: true 
},{ 
    id: 506, 
    text: 'ifOutDiscards', 
    leaf: true 
},{ 
    id: 507, 
    text: 'ifInErrors', 
    leaf: true 
},{ 
    id: 508, 
    text: 'ifOutOctets', 
    leaf: true 
},{ 
    id: 509, 
    text: 'ifOutErrors', 
    leaf: true 
},{ 
    id: 510, 
    text: 'ifInUcastpkts', 
    leaf: true 
},{ 
    id: 511, 
    text: 'ifInNUcastpkts', 
    leaf: true 
}]},{ 
    id: 487, 
    text: 'dskIndex', 
    children: [{ 
id: 488, 
text: '('1',)', 
children : [{ 
    id: 489, 
    text: 'ns-dskUsed', 
    leaf: true 
},{ 
    id: 490, 
    text: 'ns-dskPercent', 
    leaf: true 
},{ 
    id: 491, 
    text: 'ns-dskAvail', 
    leaf: true 
},{ 
    id: 492, 
    text: 'ns-dskTotal', 
    leaf: true 
}]},{ 
id: 493, 
text: '('2',)', 
children : [{ 
    id: 494, 
    text: 'ns-dskUsed', 
    leaf: true 
},{ 
    id: 495, 
    text: 'ns-dskPercent', 
    leaf: true 
},{ 
    id: 496, 
    text: 'ns-dskAvail', 
    leaf: true 
},{ 
    id: 497, 
    text: 'ns-dskTotal', 
    leaf: true 
}]}]}] 
나는 문제가 무엇인지 알아낼 수 없습니다

, 괄호는 제대로 균형 불을 지르고해야한다 오류가 발생하지 않습니다. 이 끈이 잘 형성되어 있지 않습니까? 아니면 내 treepanel이 작동하지 않는 또 다른 방법이 있습니까? 제공된 도움을 주셔서 대단히 감사합니다!

답변

0

id가 501 인 노드의 부분 인 text: e,을 보셨습니까? id: 488, text: '('1',)'id: 493, text: '('2',)',과 동일한 문제입니다. 이러한 문자열은 잘못된 형식으로 전달됩니다. 그것들을 고치면 ExtJS가 (로컬에서 시도한) 트리를 만들 수 있습니다.

찾고있는 오류는 eval 문에 있습니다. ExtJS는 백그라운드에서 서버의 응답을 평가하려고 시도하며 잘못 형성된 json으로 인해 응답하지 않습니다.

json.org에서 json 형식을 읽을 수 있습니다.

파이썬 2.6부터 시작하여 파이썬 json encoder이 있습니다. json을 생성하기 위해 의존 할 수 있습니다.

1

데이터에 jsonlint을 실행하면이 오류가 표시됩니다. 문제를 해결하고 코드를 다시 실행하십시오.

Parse error on line 2: 
[ {  id: 476,  tex 
--------------^ 
Expecting 'STRING', '} 
+0

죄송합니다 .. jsonlint의 결과를 맹목적으로 게시했습니다. 다른 점은 Li0liQ가 지적한 바와 같이 불쾌 해 보이는 것 같습니다. 그 문제를 해결하고 다시 시도하십시오 .. –

+1

이것은 json의 형식을 지정하고 유효성을 검사하는 데 더 효과가있는 것 같습니다. http://www.freeformatter.com/json-formatter.html 오류는 "JSON 입력이 JavaScript에서 유효하지 않음, 속성 목록 (라인 # 269), (위치 # 11)에서 " –