0

嗨,我是 Sencha touch 的新手,我有一个问题。我查找了我能找到的关于我的问题的所有答案,并尝试了所有这些答案,但我错过了一些东西。

我想在我的视图中添加一个带有一些文本字段和列表的面板。但是我的列表总是在后台,我不能再点击它了。

图片:

问题的图像

这是代码:

Ext.define("NotesApp.view.TestPanel", {
extend: "Ext.Panel",
alias: "widget.testpanel",



config: {
    listeners: [{
        delegate: '#logOutButton',
        event: 'tap',
        fn: 'onLogOutButtonTap'
    }],
    layout: {
        type: 'fit',
    fullscreen: true
    }
},

initialize: function () {

    this.callParent(arguments);

    var logOutButton = {
            xtype: "button",
            text: 'Log Out',
            ui: 'action',
    }

    var form = Ext.create
    (
        'Ext.form.Panel', 
        {
            config:
            {
                layout: 'fit',
                height: '300px',
            },
            items: 
            [
                {
                    xtype: 'textfield',
                    name: 'name',
                    label: 'Name'
                },
                {
                    xtype: 'emailfield',
                    name: 'email',
                    label: 'Email'
                },
                {
                    xtype: 'passwordfield',
                    name: 'password',
                    label: 'Password'
                },
            ]
        }
    );


    var newButton = {
        xtype: "button",
        text: 'New',
        ui: 'action',
        handler: this.onNewButtonTap,
        scope: this
    };

    var notesList = {
            xtype: "noteslist",
        layout: 'fit',
            store: Ext.getStore("Notes"),
            listeners: {
                disclose: { fn: this.onNotesListDisclose, scope: this }
            }
        };

    var topToolbar = {
        xtype: "toolbar",
        title: 'My Notes',
        docked: "top",
        items: [logOutButton, {xtype: 'spacer'}, newButton]
        };

    var bottomToolbar =
    {
        xtype: "toolbar",
        docked: "bottom",
        layout:
        {
            type: 'hbox',
            pack: 'center'
        },
        items:
        [
            {
                xtype: "button",
                text: "testButton",
                width: "100"
            }
        ]
    }
        this.add([topToolbar,notesList, form, bottomToolbar]);
},
onNewButtonTap: function() {
    this.fireEvent("newNoteCommand", this);
},

onNotesListDisclose: function (list, record, target, index, evt, options) {
        console.log("editNoteCommand");
        this.fireEvent('editNoteCommand', this, record);
    },

onLogOutButtonTap: function () {
    this.fireEvent('signOutCommand')
}
});

控制器:

Ext.define("NotesApp.controller.Notes", {

extend: "Ext.app.Controller",
config: {
    refs: {

        notesListContainer: "noteslistcontainer",
        noteEditor: {
            selector: 'noteeditor',
            xtype: 'noteeditor',
            autoCreate: true
            },

    },
    control: {
        notesListContainer: {

            newNoteCommand: "onNewNoteCommand",
            editNoteCommand: "onEditNoteCommand"
                },

        noteEditor: {
        saveNoteCommand: "onSaveNoteCommand",
        deleteNoteCommand: "onDeleteNoteCommand",
        backToHomeCommand: "onBackToHomeCommand"
                    }
            }
        },

    slideLeftTransition: { type: 'slide', direction: 'left' },
    slideRightTransition: { type: 'slide', direction: 'right' },

    getRandomInt: function (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
},
activateNoteEditor: function (record) {

    var noteEditor = this.getNoteEditor();
    noteEditor.setRecord(record); // load() is deprecated.
    Ext.Viewport.animateActiveItem(noteEditor, this.slideLeftTransition);
},
activateNotesList: function () {
    Ext.Viewport.animateActiveItem(this.getNotesListContainer(), this.slideRightTransition);
},

        onNewNoteCommand: function() {
            var now = new Date();
            var noteId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString();

            var newNote = Ext.create("NotesApp.model.Note",
        {
            id: noteId,
            dateCreated: now,
            title: "",
            narrative: ""   

        });

        this.activateNoteEditor(newNote);

        },
        onEditNoteCommand: function(list, record) {

            this.activateNoteEditor(record);


        },

        onDeleteNoteCommand: function() {
            var noteEditor = this.getNoteEditor();
            var currentNote = noteEditor.getRecord();
            var notesStore = Ext.getStore("Notes");

            notesStore.remove(currentNote);
            notesStore.sync();

            this.activateNotesList();
        },

        onBackToHomeCommand: function() {
            this.activateNotesList();
        },

        onSaveNoteCommand: function() {
            var noteEditor = this.getNoteEditor();
            var currentNote = noteEditor.getRecord();
            var newValues = noteEditor.getValues();

            currentNote.set("title", newValues.title);
            currentNote.set("narrative", newValues.narrative);

            var errors = currentNote.validate();

            if (!errors.isValid()) {
                     Ext.Msg.alert('Wait!', errors.getByField("title")[0].getMessage(), Ext.emptyFn);
                     currentNote.reject();
                     return;
                }

            var notesStore = Ext.getStore("Notes");

            if (null == notesStore.findRecord('id', currentNote.data.id)) {
                        notesStore.add(currentNote);
                    }

                    notesStore.sync();

                    notesStore.sort([{ property: 'dateCreated', direction: 'DESC'}]);
                    this.activateNotesList();
                },




        launch: function() {
            this.callParent(arguments);
                Ext.getStore("Notes").load();


        },
        init: function() {
            this.callParent(arguments);
        }

    });

和清单:

Ext.define("NotesApp.view.NotesList", {
extend: "Ext.dataview.List",
alias: "widget.noteslist",
config: 
{
    loadingText: "Loading Notes...",
    emptyText: "<div class=\"notes-list-empty-text\">No notes found.</div>",
    onItemDisclosure: true,
    grouped: true,
    itemTpl: "<div class=\"list-item-title\">{title}</div><div class=\"list-item-narrative\">{narrative}</div>",        
},


});
4

1 回答 1

0

很难告诉您如何在没有控制器的情况下解决问题,因为我无法模拟上述问题。但这是我根据我测试的提供的代码的预感,问题可能源于面板的滥用。由于面板是所有浮动和模态的基础,这不是您在这种情况下想要的(这是 Sencha 在动作状态 pg76 中所触及的)。笔记列表的布局也很合适,但您没有说明高度。fit 采用其父级的高度,但当您使用 add 时,我们不知道父级高度是多少。最后,我建议您从初始化函数中取出所有内容并将其放入配置项中,就像我在下面所做的那样(现在请记住最后一个是建议)祝您好运:)

        config : {
            listeners : [ {
                delegate : '#logOutButton',
                event : 'tap',
                fn : 'onLogOutButtonTap'
            } ],
            items : [ {
                xtype : "toolbar",
                title : 'My Notes',
                docked : "top",
                items : [ {
                    xtype : "button",
                    text : 'Log Out',
                    ui : 'action',
                }, {
                    xtype : 'spacer'
                }, {
                    xtype : "button",
                    text : 'New',
                    ui : 'action',
                    handler : this.onNewButtonTap,
                    scope : this
                } ]
            }, {
                xtype : 'textfield',
                name : 'name',
                label : 'Name'
            }, {
                xtype : 'emailfield',
                name : 'email',
                label : 'Email'
            }, {
                xtype : 'passwordfield',
                name : 'password',
                label : 'Password'
            }, {
                xtype : "toolbar",
                docked : "bottom",
                layout : {
                    type : 'hbox',
                    pack : 'center'
                },
                items : [ {
                    xtype : "button",
                    text : "testButton",
                    width : "100"
                } ]
            }, {
                // xtype : "noteslist",
                layout : 'vbox',
                store : Ext.getStore("Notes"),
                listeners : {
                    disclose : {
                        fn : this.onNotesListDisclose,
                        scope : this
                    }
                }
            } ]
        }

仅供参考,我刚刚从初始化中删除了所有内容,然后离开了 this.callParent(arguments); 但我认为您也不需要它,因为这将调用其父构造函数

于 2013-09-30T15:29:45.450 回答