Extjs json获取动态数据及静态数据

一、获取静态数据:

var store = Ext.create('Ext.data.JsonStore', {
  fields     : ['id', 'title', 'items'],
  data       : catalog
  

 })

var catalog = Platform.app.serversCatalog;

Platform.app = {
  serversCatalog: [
       {
               "id": "subsys",
         "title": "10.24.1.18",
         "items": [
          {
           "id": "'opermain'",
           "text": "subsys",
           "url": "'front'",
           "ip":"'10.24.1.18'",
           "icon": "front.png",
           "desc": "子系统",
           "status": "online"
          },
          {
           "id": "'front'",
           "text": "front",
           "url": "'front'",
           "ip":"'10.24.1.18'",
           "icon": "front.png",
           "desc": "前台柜面",
           "status": "online"
          }
         ]
       }
   
  ]
 };

二、json从后台获取动态数据:

var store = Ext.create('Ext.data.JsonStore', {
        fields     : ['id', 'title', 'items'],
        proxy: {
            type: 'ajax',
            url: '../../../subSystemServlet.do?',
            reader: {
                type: 'json',
                root: 'root'
            }
        }
    });

   store.load();

后台:

String result="[\r\n"+
   "{\r\n"+
     "\"title\": \"127.0.0.1\","+
     "\"items\": ["+
      "{"+
       "\"id\": \"\'opermain\'\","+
       "\"text\": \"subsys\","+
       "\"url\": \"\'front\'\","+
       "\"ip\":\"\'10.24.1.18\'\","+
       "\"icon\": \"front.png\","+
       "\"desc\": \"子系统\","+
       "\"status\": \"online\""+
      "},"+
      "{"+
       "\"id\": \"\'front\'\","+
       "\"text\": \"front\","+
       "\"url\": \"\'front\'\","+
       "\"ip\":\"\'10.24.1.18\'\","+
       "\"icon\": \"front.png\","+
       "\"desc\": \"前台柜面\","+
       "\"status\": \"online\""+
      "}"+
     "]"+
   "},"+
   "{"+
     "\"title\": \"10.24.1.32\","+
     "\"items\": ["+
      "{"+
       "\"id\": \"\'cnaps1\'\","+
       "\"text\": \"cnaps1\","+
       "\"url\": \"\'cnaps1\'\","+
       "\"ip\":\"\'10.24.1.32\'\","+
       "\"icon\": \"cnaps1.gif\","+
       "\"desc\": \"一代支付系统\","+
       "\"status\": \"down\""+
      "}"+
     "]"+
   "}"+
"]";

req.setCharacterEncoding("gbk");
  resp.setContentType("text/json; charset=GBK"); 
  resp.getWriter().println(result);

ext

相关推荐