2011-06-04 3 views
1

Je suis nouveau dans Ext et j'ai un problème: je suis en train de remplir ExtJS-grille avec des données:Problème avec la grille de remplissage ext avec JSON valeurs

Ext.onReady(function() { 
     var store = new Ext.data.JsonStore({ 
      root: 'topics', 
      totalProperty: 'totalCount', 
      idProperty: 'threadid', 
      remoteSort: true, 
      autoLoad: true, /// 

      fields: [ 
       'title', 'forumtitle', 'forumid', 'author', 
       {name: 'replycount', type: 'int'}, 
       {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'}, 
       'lastposter', 'excerpt' 
      ], 

      proxy: new Ext.data.ScriptTagProxy({ 
      url:'http://10.10.10.101:8080/myproject/statusList/getJobs/2-10/search-jobname-/sort-asdf/filterjobname-123/filterusername-davs/filterstatus-completed/filtersubmdate-today', 
      method : 'GET' 
     }) 
    }); 

    // 
    var cm = new Ext.grid.ColumnModel([ 
     {sortable:true, id : 'id',   dataIndex:'id'}, 
     {sortable:true, id : 'title',  dataIndex:'title'}, 
     {sortable:true, id : 'forumtitle', dataIndex:'forumtitle'}, 
     {sortable:true, id : 'forumid',  dataIndex:'forumid'}, 
     {sortable:true, id : 'author',  dataIndex:'author'} 
    ]); 

    var grid = new Ext.grid.GridPanel({ 
     id: 'mainGrid', 
     el:'mainPageGrid', 
     pageSize:10, 
     store:store, 
     // stripeRows: true, 
     cm:cm, 
     stateful: false, // skipSavingSortState 
     viewConfig:{ 
      forceFit:true 
     }, 
     //  width:1000, 
     //  height:700, 
     loadMask:true, 
     frame:false, 

     bbar: new Ext.PagingToolbar({ 
      id : 'mainGridPaginator', 
      store:store, 
      hideRefresh : true, 
      plugins: new Ext.ux.Andrie.pPageSize({ 
       beforeText: 'View: ', 
       afterText: '', 
       addAfter: '-', 
       variations: [10, 25, 50, 100, 1000] 
       //comboCfg: { 
        //id: '${ dispview_widgetId }_bbar_pageSize' 
       //} 
      }), 
      displayMsg: 'Displaying items {0} - {1} of {2}', 
      emptyMsg:'No data found', 
      displayInfo:true 
     }) 
    }); 

    grid.render(); 
}); 

et la partie Java:

@GET 
@Path("/getJobs/{startFrom}-{startTo}/search-{searchType}-{searchName:.*}/" + 
     "sort-{sortType}/filterjobname-{filterJobName:.*}/filterusername-{filterUsername:.*}/" + 
     "filterstatus-{filterStatus:.*}/filtersubmdate-{filterSubmittedDate:.*}") 
@Produces({"application/json"}) 
@Encoded 
public String getJobs(
     @PathParam("startFrom")    String startFrom, 
     @PathParam("startTo")    String startTo, 
     @PathParam("searchType")   String searchType, 
     @PathParam("searchName")   String searchName, 
     @PathParam("sortType")    String sortType, 
     @PathParam("filterJobName")   String filterJobName, 
     @PathParam("filterUsername")  String filterUsername, 
     @PathParam("filterStatus")   String filterStatus, 
     @PathParam("filterSubmittedDate") String filterSubmittedDate) { 


    return "{totalCount:'3',topics:[{title:'XTemplate with in EditorGridPanel',threadid:'133690',username:'kpremco',userid:'272497',dateline:'1305604761',postid:'602876',forumtitle:'Ext 3x Help',forumid:'40',replycount:'2',lastpost:'1305857807',lastposter:'kpremco',excerpt:'Hi I have an EditiorGridPanel whose one column i am using XTemplate to render and another Column is Combo Box FieldWhen i render the EditorGri'}," + 
              "{title:'IFrame error _flyweights is undefined',threadid:'133571',username:'Daz',userid:'52119',dateline:'1305533577',postid:'602456',forumtitle:'Ext 3x Help',forumid:'40',replycount:'1',lastpost:'1305857313',lastposter:'Daz',excerpt:'For Ext 330 using Firefox 4 Firebug, the following error is often happening when our app loads e._flyweights is undefined Yetthis '}," + 
              "{title:'hellllllllllllllpwhy it doesnt fire cellclick event after I change the cell value',threadid:'133827',username:'aimer311',userid:'162000',dateline:'1305700219',postid:'603309',forumtitle:'Ext 3x Help',forumid:'40',replycount:'3',lastpost:'1305856996',lastposter:'aimer311',excerpt:'okI will discribe this problem as more detail as I canI look into this problem for a whole dayI set clicksToEdit1 to a EditorGridPanelso when I'}]}"; 

en conséquence, je reçois une erreur JavaScript:

Syntax error at line 1 while loading: 
totalCount:'3',topics:[{title:'XTemplate 
---------------------^ 
expected ';', got ':' 

Bien que, lorsque j'utilise l'URL Proxy:Ce qui représente la même information, je n'ai aucun problème.

Où est mon échec ????

P.S. Commentaires pour la première réponse:

return "{\"totalCount\":\"3\",\"topics\":[{\"title\":\"XTemplate with in EditorGridPanel\",\"threadid\":\"133690\",\"username\":\"kpremco\",\"userid\":\"272497\",\"dateline\":\"1305604761\",\"postid\":\"602876\",\"forumtitle\":\"Ext 3x Help\",\"forumid\":\"40\",\"replycount\":\"2\",\"lastpost\":\"1305857807\",\"lastposter\":\"kpremco\",\"excerpt\":\"Hi I have an EditiorGridPanel whose one column i am using XTemplate to render and another Column is Combo Box FieldWhen i render the EditorGri\"}," + 
              "{\"title\":\"IFrame error _flyweights is undefined\",\"threadid\":\"133571\",\"username\":\"Daz\",\"userid\":\"52119\",\"dateline\":\"1305533577\",\"postid\":\"602456\",\"forumtitle\":\"Ext 3x Help\",\"forumid\":\"40\",\"replycount\":\"1\",\"lastpost\":\"1305857313\",\"lastposter\":\"Daz\",\"excerpt\":\"For Ext 330 using Firefox 4 Firebug, the following error is often happening when our app loads e._flyweights is undefined Yet, this \"}," + 
              "{\"title\":\"hellllllllllllllpwhy it doesn't fire cellclick event after I change the cell value\",\"threadid\":\"133827\",\"username\":\"aimer311\",\"userid\":\"162000\",\"dateline\":\"1305700219\",\"postid\":\"603309\",\"forumtitle\":\"Ext 3x Help\",\"forumid\":\"40\",\"replycount\":\"3\",\"lastpost\":\"1305856996\",\"lastposter\":\"aimer311\",\"excerpt\":\"okI will discribe this problem as more detail as I canI look into this problem for a whole dayI set clicksToEdit1 to a EditorGridPanelso when I\"}]}"; 

J'ai l'erreur suivante:

Syntax error at line 1 while loading: 
{"totalCount":"3","topics":[{"title 
-------------^ 
expected ';', got ':' 

post-scriptum # 2. Lorsque j'ai ajouté '[' au début de la chaîne de réponse et ']' à la fin, les erreurs ont disparu, mais la grille n'a pas été remplie de données

Répondre

0

J'ai trouvé la racine du problème. Comme je l'ai connu Ext send à ma fonction de service Web avec le paramètre 'callback = [some_callback_name]' (par exemple callback1001). Cela signifie qu'Extjs veut obtenir des résultats non seulement au format JSON, mais au format 'callback1001()'. Quand j'ai renvoyé mes données dans ce format tout est devenu bon.Vous n'êtes toujours pas:

liens Preuve:

2

Vous ne renvoyez pas (valide) JSON. Reportez-vous au JSON site pour plus de détails, mais par exemple, toutes les clés de propriété doivent être entre guillemets. (Toutes les chaînes doivent être entre guillemets, guillemets simples ne sont pas valables pour les chaînes JSON.)

Ainsi, par exemple, cela est pas JSON valide:

{totalCount:'3'} 

... parce que la clé est pas entre guillemets, et la valeur utilise des guillemets simples. Le bon JSON serait:

{"totalCount":"3"} 

... si vous voulez vraiment la 3 d'être une chaîne, ou:

{"totalCount":3} 

... si le 3 doit être un nombre.

Les gens confondent souvent la notation littérale d'objet JSON et JavaScript, mais ils sont différents. Plus précisément, JSON est un sous-ensemble de la notation littérale d'objet. Un grand nombre de choses qui sont valides dans la notation littérale d'objet ne sont pas valides dans JSON. En cas de doute, vous pouvez vérifier au jsonlint.com, qui fournit un validateur JSON approprié.

+0

J'ai commenté en fin de ma question – davs

+0

@davs renvoyer un JSON valide (vous avez manqué certaines citations, par exemple autour de "sujets", et il peut y avoir d'autres problèmes). Donc, la première chose à faire est de s'assurer que vous renvoyez vraiment un JSON valide. Je soupçonne qu'il se passe quelque chose d'autre, mais c'est la première étape. –

+0

Merci beaucoup pour le validateur JSON, j'ai encore changé la chaîne de retour, mais même si elle dit que le JSON est valide, j'ai des problèmes .... – davs

Questions connexes