2012-11-09 153 views
2

我最近开发了一个关于显示类别/子类别的sencha应用程序。它显示主要类别,但不会在单击任何类别时显示子类别。在sencha中显示类别/子类别

我的店is--

Ext.define('listdemo.store.Sections', { 
extend : 'Ext.data.Store', 

config : { 
    autoLoad: true, 
    model: 'listdemo.model.Sections', 

    proxy:{ 
     type : 'ajax', 
     url:'http://localhost/catt.php', 

     reader:{ 
        type:'json', 
        rootProperty:'categories'  
       } 

    } 
} 
}); 

型号代码------

Ext.define('listdemo.model.Sections', { 
extend: 'Ext.data.Model', 

config: { 
    fields: ['categories_id', 'categories_name','subcategories'], 


} 
}); 

而且观点是----

Ext.define('listdemo.view.Main',{ 
     extend: 'Ext.NestedList', 
     xtype:'main', 
     requires: [ 
      'Ext.TitleBar', 
      'Ext.dataview.List', 
      'Ext.data.Store', 
      'Ext.dataview.NestedList' 
     ], 

     config:{ 
      title: 'Categories', 
      //store:'Sections', 
      items:[ 
      { 
       xtype:'list', 
       itemTpl:'{categories_name}', 
       title:'Categories', 
       store:'Sections', 

      } 
     ] 
    } 
}); 

我的PHP文件回报----

{ “类别”:[{ “categories_id”: “1”, “categories_name”: “硬件”, “子类别”:[{ “categories_id”: “4”, “categories_name”: “图形 卡”},{ “categories_id”: “5”, “categories_name”: “打印机”},{ “categories_id”: “6”, “categories_name”: “监视器”},{ “categories_id”: “7”, “categories_name”:“扬声器“},{” categories_id “:” 8" , “categories_name”: “键盘”},{ “categories_id”: “9”, “categories_name”: “小鼠”},{ “categories_id”: “16”,“categories_name “:”Memory“},{”categories_id“:”17“,”categories_name“:”CDROM Drives“}]},{”categories_id“:”2“,”categories_name“:”Software“,”subcategories“ [{ “categories_id”: “18”, “categories_name”: “模拟”},{ “categories_id”: “19”, “categories_name”: “动作”},{ “categories_id”: “20”, “categories_name”: “策略”}}},{“categories_id”:“3”,“categories_name”:“DVD 电影”,“子类别”:[{“categories_id”:“10”,“categories_name”:“Action”}, “categories_id”: “11”,“categories_n AME “:” 科学 虚构 “},{” categories_id “:” 12" , “categories_name”: “喜剧”},{ “categories_id”: “13”, “categories_name”: “卡通”},{ “categories_id” :“14”,“categories_name”:“Thriller”},{“categories_id”:“15”,“categories_name”:“Drama”}]}]}

我将如何显示子类别在主要类别下。

回答

0

您需要更新模型定义以包含字段类型,并注册要用于子类别的自定义数据类型。

开始由模型加载之前,包括这样的:

Ext.data.Types.ARRAY = { 
    type: 'Array' 
}; 

下一次更新你的模型,看起来像这样:

Ext.define('listdemo.model.Sections', { 
    extend: 'Ext.data.Model', 
    config: { 
     fields: [{ 
      name: 'categories_id', 
      type: 'int' 
     },{ 
      name: 'categories_name', 
      type: 'string' 
     },{ 
      name: 'subcategories' 
      type: Ext.data.Types.ARRAY 
     }] 
    } 
}); 

现在,一旦你的存储加载,手动通过Web控制台检查记录以确保保存子类别的数组。您需要在列表中添加itemtap的侦听器,然后获取子类别,然后执行以下任一操作:
使用子类别数组手动加载原始存储。这应该刷新列表,但是您将失去原始商店,并且不会有任何卡片动画。
- 设置第二个列表/商店,将手动重新加载子类别,这将允许更改卡片动画并保持原始商店的后退导航。

0
  1. 给你的店店铺ID

2。传递参数categories_name和选择其父目录是categories_name子类别 成功:功能(响应) {

searchresponse2 = Ext.JSON.decode(response.responseText); //获取从服务器响应

// searchresponse2是存储数组索引[0]中第一个结果的数组。

变种categoriesid = searchresponse2.categories; //获取第一 值 “categories_id”: “1”, “categories_name”: “硬件”

  var categoriesname=searchresponse2.categories_name; 

       del_categoriesid=[];//declaring array 
       del_categoriesname=[]; 

      for(var i= 0;i<searchresponse2.length;i++) 
       { 
        del_categoriesid[i]=searchresponse2[i].categories; 
        del_categoriesname[i]=searchresponse2[i].categories_name; 
       }// looping through all values 


       for(var j= 0;j < searchresponse2.length;j++) 
       { 

Ext.getStore( 'STOREID')添加(。 {categories:del_categoriesid [j],categories_name:del_categoriesname [j]}); } //在商店中添加结果的值