English 中文(简体)
How to use JSON without json file?
原标题:
  • 时间:2011-04-23 12:37:14
  •  标签:
  • extjs
  • extjs4

I need to use dynamically JSON with data.TreeStore. With this component, there is proxy "config", it need a path to JSON file. My problem is, i can t write Json file in my application. I would know, if i can generated JSON dynamically and pass it to url config into proxy?

For example :

Var trStore = Ext.create( Ext.Data.TreeStore ,{

... // config
proxy {

type :  ajax ,
url : { id :  id0 , task : task0 , value :  val0 , ..... }

}
});

My URL is not a file url but is JSON generated with my own method !

How to build JSON for use it with TreeStore and without make file !?

I hope you understand my problem :)

Thanks a lot to help !

问题回答

Your example looks like you want to pass static "inline data" to the TreeStore.

As far as I can see this is not possible with a bare TreeStore, since it does not have a data config option as the "normal" Store has. However, it is possible with a Treepanel.

You can pass your inline data to the TreeStore using the root config option of the Treepanel (not the TreeStore). It works in a very similar manner as the data config option of a "normal" Store:

Ext.create( Ext.tree.Panel , {
  root: { id :  id0 , task : task0 , value :  val0 , children: [...], ... }
  // ...
});

There are two caveats related to this:

  • The beta3 docs say root is boolean, that s wrong.
  • Because of a bug in beta3 you cannot use this together with rootVisible: false.

Remember that a "json file" is really just a text string, so you can generate that with PHP or your preferred server software.

For the url in the proxy, simply put in the url you use to run that function. Eg in my web app I have http://example.org/controller/getTree?output=json

This runs the getTree() function on my controller, and the function knows to return json.





相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

I have some issues with Json result and embed it within the html of the Extjs Panel. Here s that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签