繁体   English   中英

Sencha Touch 1.1 嵌套列表关联

[英]Sencha Touch 1.1 nested list associations

我有以下问题,我无法从子列表中获取数据,我做错了吗?

我的代码:

//文件 lstCabDet.txt

{"root":[
    {
    "NumeroPedido":"0000000001",
    "CodigoCliente":"100000",
    "NombreCliente":"hskjdnd",
    "NIF":"43065236",
        "Detalle":[{
        "DocumentoVenta":"0000000001",
        "Posicion":"000010",
        "CodigoMaterial":"000000000010000002",
        "Material":"Prueba material 1"}]},
    {
    "NumeroPedido":"0000000002",
    "CodigoCliente":"100000",
    "NombreCliente":"hskdsnb",
    "NIF":"43065236",
        "Detalle":[{
        "DocumentoVenta":"0000000002",
        "Posicion":"000010",
        "CodigoMaterial":"000000000010000002",
        "Material":"Prueba material 1"}]
    }]}

//Model
Ext.regModel('listaDocumentosModel', {
    fields: [
        {name: 'NumeroPedido', type: 'string'},
        {name: 'CodigoCliente',  type: 'string'},
        {name: 'NombreCliente',  type: 'string'},
        {name: 'NIF',  type: 'string'}
    ],
    associations:[
        {type: 'hasMany',
         model: 'listaDocumentoDetalleModel', name: 'listaDocumentoDetalleModel'}
    ]
});

Ext.regModel('listaDocumentoDetalleModel',
    {
    fields:[
        {name: 'DocumentoVenta',  type: 'string'},
        {name: 'Posicion',  type: 'string'},
        {name: 'CodigoMaterial', type: 'string'},
        {name: 'Material', type: 'string'}
    ],
    associations:[
        {type: 'belongsTo', model: 'listaDocumentosModel'}
    ]
});

//Store
var listaDocumentosStore = new Ext.data.Store (
{
    autoLoad: true,
    model: 'listaDocumentosModel',
    proxy:
    {
        id: 'listaDoc',
        type: 'rest',
        url: 'data/lstCabDet.txt',
        reader:
        {
            type: 'json',
            root : 'root'
        }
    }
});

//View Detail
var disDetDoc =
    '<div>'+
        '<div>'+
            '<div>{NumeroPedido}</div>'+
            '<div>{Posicion}</div>'+
            '<div>{CodigoMaterial}</div>'+
            '<div>{Material}</div>'
        '</div>'+
    '</div>';
    
detalleDocumento = Ext.extend(Ext.Panel, 
{
    layout: 'card',
    initComponent: function() 
    {
        this.dockedItems = [
        {
            xtype: 'toolbar',
            dock: 'top',
            title: 'Detalle documento',
            items: [
            {
                ui: 'back',
                text: 'Volver',
                scope: this,
                handler: function()
                {
                    this.ownerCt.setActiveItem(this.prevCard, 
                    {
                        type: 'slide',
                        reverse: true,
                        scope: this,
                        after: function()
                        {
                            this.destroy();
                        }
                    });
                }
            }]
        }];
        
        this.detalleDocPanel = new Ext.Panel(
        {
            layout: 'fit',
            
            items: [
            {
                scroll: 'vertical',
                data: this.record.data,
                tpl: disDetDoc          
            }]
        });
        
        this.items = this.detalleDocPanel;
                
        detalleDocumento.superclass.initComponent.call(this);
    }
});

Ext.reg('detalleDocumento', detalleDocumento);

//View Master
var listDoc =
    '<div class="materialItem">'+
        '<div class="list-codigo">'+
            '{NumeroPedido}'+
            '{CodigoCliente}'+
            '{NIF}'+
            '{NombreCliente}'+
        '</div>'
    '</div>';

var lblRef = [{
    xtype: 'fieldset',
    defaults: 
        {
            labelAlign: 'left',
            labelWidth: '30%'
        },
    items: [
    {
        xtype: 'textfield',
        label: 'Referencia',
        useClearIcon: true
    }]
}];

var buttonVolver = [{
    ui: 'back',
    text: 'Volver',
    handler: function()
        {
            window.open("consultaDoc.html","_self");
        }
    },
    {
        xtype: 'spacer'
    }
]

var dockedItems = [{
    xtype: 'toolbar',
    title: 'Lista de documentos',
    dock: 'top',
    ui: 'dark',
    items: buttonVolver
}]



listaDocumentoView = Ext.extend(Ext.Panel, 
{
    fullscreen: true,
    layout: 'card',     
    initComponent: function() 
    {
        this.lDoc = new Ext.List({
            id: 'listaDoc',
                grouped: false,
                itemTpl: listDoc,
                loadingText: false,
                store: listaDocumentosStore 
        });
        
        this.lDoc.on('selectionchange', this.onSelect, this);
        
        this.listaDocumentosPanel = new Ext.Panel(
        {   
            layout: 'fit',
            dockedItems: dockedItems,
            items: this.lDoc,
            listeners: 
            {
                activate: 
                { 
                    fn: function()
                    {
                        this.lDoc.getSelectionModel().deselectAll();
                        Ext.repaint();
                    }, 
                    scope: this 
                }
            }
        });
        
        this.items = this.listaDocumentosPanel;
        
        listaDocumentoView.superclass.initComponent.call(this);
    },
        
    onSelect: function(selectionmodel, records)
    {
        if (records[0] !== undefined) 
        {
           var detalleDocCard = new detalleDocumento(
           {
               prevCard: this.listaDocumentosPanel,
               record: records[0]
           });

           this.setActiveItem(detalleDocCard, 'slide');
        }
    }
});

Ext.reg('listaDocumentoView', listaDocumentoView);

我正在处理同样的问题。 也许这可以帮助您更接近解决方案:

访问 JSON 提要中的嵌套对象 - Sencha Touch答案:

Ext.regModel('MODEL', {
    fields: [{name:'position', mapping:'NIF.postion'}]

});

将您的模型更改为

Ext.regModel('listaDocumentosModel', {
fields: [
    {name: 'NumeroPedido', type: 'string'},
    {name: 'CodigoCliente',  type: 'string'},
    {name: 'NombreCliente',  type: 'string'},
    {name: 'NIF',  type: 'string'}
],
hasMany:[
    { model: 'listaDocumentoDetalleModel', name: 'listaDocumentoDetalleModel', , associationKey: 'listaDocumentoDetalleModel'}
]});

并从子模型中删除此行

associations:[
    {type: 'belongsTo', model: 'listaDocumentosModel'}
]

这个修改解决了我同样的问题,希望这对你有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM