2013-06-24 37 views
2

我有一个json字符串,我想通过php url获取它在extjs的网格存储中。如何从php文件中将这个字符串作为json返回。 是这样的:如何将静态JSON从PHP返回到extjs存储

var store = Ext.create('Ext.data.Store', { 
    id: 'store', 
    model: 'ForumThread', 
    remoteGroup: true, 
    buffered: true, 
    leadingBufferZone: 300, 
    pageSize: 100, 
    proxy: { 
     type: 'jsonp', 
     url: 'myJsonPhp.php', //this file should return json. 
     reader: { 
      root: 'topics', 
      totalProperty: 'totalCount' 
     }}, 
    autoLoad: true 
}); 

我知道有一些方法来从PHP返回JSON,但他们创建并返回JSON。我已经有JSON ..

* JSON字符串:*

{"totalCount":"6679","topics":[{"title":"XTemplate with in EditorGridPanel","threadid":"133690","username":"[email protected]","userid":"272497","dateline":"1305604761","postid":"602876","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"2","lastpost":"1305857807","excerpt":""},{"title":"IFrame error "_flyweights is undefined"","threadid":"133571","username":"Daz","userid":"52119","dateline":"1305533577","postid":"602456","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"1","lastpost":"1305857313","excerpt":""},{"title":"Status bar error with IFrames","threadid":"134120","username":"Daz","userid":"52119","dateline":"1305857168","postid":"604220","forumtitle":"Ext 3.x: Bugs","forumid":"41","replycount":"0","lastpost":"1305857168","excerpt":""},{"title":"hellllllllllllllp,why it doesn't fire cellclick event after I change the cell value??","threadid":"133827","username":"aimer311","userid":"162000","dateline":"1305700219","postid":"603309","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"3","lastpost":"1305856996","excerpt":""},{"title":"Extjs 4.0 support for IE9","threadid":"122352","username":"extdev22","userid":"48017","dateline":"1296097557","postid":"565503","forumtitle":"Ext: Open Discussion","forumid":"6","replycount":"30","lastpost":"1305841535","excerpt":""},{"title":"Using XTemplate to send XML","threadid":"134102","username":"cayenne_08","userid":"237393","dateline":"1305841170","postid":"604153","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"0","lastpost":"1305841170","excerpt":""},{"title":"Open Source Development - The people you interact with....","threadid":"134093","username":"watrboy00","userid":"9862","dateline":"1305837814","postid":"604114","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305837814","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134091","username":"Andrew.Golik","userid":"32056","dateline":"1305837033","postid":"604102","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305837033","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134090","username":"Andrew.Golik","userid":"32056","dateline":"1305836975","postid":"604100","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305836975","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134089","username":"Andrew.Golik","userid":"32056","dateline":"1305836900","postid":"604099","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305836900","excerpt":""}]} 

回答

1

最简单的解决方法就是直接返回字符串到响应(并设置内容类型的课程):

<?php 

header("Content-Type: application/json"); 

print $my_json_string; 

?>