2011-10-28 3 views
1

imdb에서 데이터를로드하려고하는데 테이블 (GridPanel)에 결과가 없습니다. 그것은 내 소스 코드입니다 : ExtJs loading data

... 
<body> 
<script type="text/javascript"> 
Ext.onReady(function(){ 

var store1 = new Ext.data.JsonStore({ 
    root: 'root', 
    idProperty: 'ID', 
    remoteSort: true, 
    fields: [ 
     'Title' 
    ], 
    // load using script tags for cross domain, if the data in on the same domain as 
    // this page, an HttpProxy would be better 
    proxy: new Ext.data.ScriptTagProxy({ 
     url: 'http://www.imdbapi.com/?t=True%20Grit' 
    }) 
}); 
// building grid panel 
}); 
</script> 
<div id="topic-grid"></div> 
... 

어쩌면 내가 JsonStore에서 '루트'매개 변수 변경해야

?


UPDATE

나는 여전히 결과에서 httpProxy를 사용하려고하지 않지만. 내 몸 전체 내용을 넣으면 더 도움이 될지도 몰라.

<script type="text/javascript"> 
Ext.onReady(function(){ 

var store1 = new Ext.data.JsonStore({ 

    reader: new Ext.data.JsonReader({ 
     fields: ['Title'], 
     root: 'rows' 
     }), 

    // load using script tags for cross domain, if the data in on the same domain as 
    // this page, an HttpProxy would be better 
    proxy: new Ext.data.HttpProxy({ 
     url: 'http://www.imdbapi.com/?t=True%20Grit' 
    }), 
    autoLoad: true 
    }); 

var grid1 = new Ext.grid.GridPanel({ 
    width:700, 
    height:500, 
    title:'ExtJS.com - Browse Forums', 
    store: store1, 
    trackMouseOver:false, 
    disableSelection:true, 
    loadMask: true, 

    // grid columns 
    columns:[{ 
     id: 'Title', 
     header: "Topic", 
     dataIndex: 'Title', 
     width: 420, 
     sortable: true 
    }] 
}); 


// render it 
grid1.render('topic-grid'); 

// trigger the data store load 
store1.load({params:{start:0, limit:25}}); 
}); 
</script> 
<div id="topic-grid"></div> 

답변

3

ScriptTagProxy를 사용할 때 응답에서 직접 JSON을 가져올 수 없습니다. 당신은 오직 실행 가능한 자바 스크립트를 얻을 수 있으며, 불행하게도 imdbapi 사이트는 실행 가능한 자바 스크립트를 반환하지 않습니다. 또한 HttpProxy를 사용하여 XSS (Cross-Site Scripting)를 수행 할 수도 없습니다. 로컬 도메인의 리소스 (예 : 파일)에만 연결할 수 있습니다. 당신을 위해

하나의 가능성 :

  1. 프록시가 연결됩니다 자신의 도메인에 서버 측 파일을 설정합니다.
  2. ScriptTagProxy 대신 서버 측 파일에 연결하는 HttpProxy를 사용하십시오.

    proxy: new Ext.data.HttpProxy({ 
        url: '/path/to/my/server/file?t=True%20Grit' // the leading slash in 
                    // this url will begin from 
                    // your web server's root 
                    // directory for your 
                    // web-accessible files 
    }) 
    
  3. 는 서버 측 파일이 클라이언트와 출력을 클라이언트로 다시 JSON으로 IMDB API의 결과를 대신하여 IMDB API 호출을하게한다.
    myServerSideFile 
    ================ 
    
    // harvest GET parameters, e.g., in your case, the query param 't' with value 
    // True%20Grit 
    
    // use the GET parameters to form a url with the GET params on the end, e.g., 
    // in your case, http://www.imdbapi.com/?t=True%20Grit 
    
    // call the imdb api using this url 
    
    // return the imdb api results as a JSON 
    

은 자세한 내용과 다양한 서버 측 기술에서 위의 제안을하는 예는 this를 참조하십시오.

+0

-1 단지 PHP 예제를 언급합니다. 사용 가능한 서버 측 언어가 더 많이 있으며 질문에는 PHP로 태그가 지정되어 있지 않습니다. 구체적인 언어는 언급하지 않아야합니다. 이 문제를 해결하면 +1로 변경됩니다. – sra

+0

@sra PHP 참조를 제거하기 위해 편집했습니다 – Ryan

+0

@ Ryan, 정보 주셔서 감사합니다. 그러나 저는 여전히 빈 테이블을 얻고 있습니다. – bontade