javascript - 如何在 Sencha touch 中滑动多个屏幕

标签 javascript json sencha-touch jsonp extjs

我正在开发一个应用程序,当在表单中单击提交按钮时,它应该转到另一个屏幕。然而,它只是在窗口外打印结果,并没有真正转到新屏幕。我对商店进行了硬编码,以确保在我启动应用程序时有数据,并且它仍将其打印在可视区域之外。

这是我的 Ext.data.Store:

var store = new Ext.data.Store({
  model: 'jobSummary',
  storeId: 'jobStore',
  data : [{title: 'This is test'},
    {title: 'This is test2'},
    {title: 'This is test3'}]
});

这是我正在使用它的列表:

SearchJobsForm.jobsList = Ext.extend(Ext.Panel, {
  dockedItems : [ {
    xtype : 'toolbar',
    title : 'WTJ',
    dock : 'top',
    items : [ {
      xtype : 'button',
      text : 'Back',
      ui : 'back',
      handler : function() {
        //back button controller
      },
      scope : this
    } ]
  } ],
  items : [ {
    xtype : 'list',
    emptyText : 'No data available.',
    store : 'jobStore',
    itemTpl : '<div class="list-item-title">{title}</div>' 
    +
      '<div class="list-item-narrative">{narrative}</div>',
    onItemDisclosure : function(record) {
    },
    grouped : false,
    scroll : 'vertical',
    fullscreen : true
  } ],
  initComponent : function() {
    SearchJobsForm.jobsList.superclass.initComponent.apply(this, arguments);
  }
});

我从我的提交按钮处理程序调用这个列表面板,它是:

var jobsList = new SearchJobsForm.jobsList();

我已将完整代码粘贴到此链接上以提高可见性: http://pastebin.com/a05AcVWZ

最佳答案

好的,

SearchJobsForm.form 是您的主面板,它将包含两个组件 searchForm(带有文本/选择输入)和一个面板/结果列表。 在回调中,我们将 hide() 表单和 show() 结果列表。这不是一个干净的代码,而是我能从你那里得到的最简单、最亲切的代码。

  • 首先让我们实例化jobsList

//它有 id ( id: 'jobsListId')

var jobsList = new SearchJobsForm.jobsList();
  • 那么你应该将所有输入放入一个表单中(xtype : formpanel, id: 'searchFormId')
  • 然后在表单后面添加resultPanel

这是代码

SearchJobsForm.form = Ext.extend(Ext.Panel,{

    initComponent: function(){

        Ext.apply(this, {
            id: 'searchForm',
            floating: true,
            width: 250,
            height: 370,
            scroll: 'vertical',
            centered: true,
            modal: true,
            hideOnMaskTap: false,
            items: [
            {
                xtype: 'formpanel', // 1. this is the added formpanel
                itemId: 'searchForm',
                id:  'searchFormId', // this id is important
                items: [
                {  
                    xtype: 'textfield',
                    ...
                }, {
                    xtype: 'textfield',
                    ...

                },
                // all your inputs 
                ]
            },
                // 2. add here the results panel : jobsList
                jobsList
            ],  // the code continues inchanged
                dockedItems: [{
                              ...

- 最后我们将修改 ajax 回调以隐藏/显示面板。不要删除其中之一,在其他地方您将无法重置表单

//来了

        Ext.util.JSONP.request({
            url: "http://"+serverAdd+":"+ port+"/users/searchresults.json", 
            format: 'json',
            callbackKey: 'callback',
            params : searchCriteria,                
            callback: function(data) {
                console.log('callback');
                // Call your list-filling fonctions here
                // jobsList.fill(data);
                Ext.getCmp('searchFormId').hide();
                Ext.getCmp('jobsListId').show();

            },
            failure: function ( result) { 
                console.error('Failed'); 
            }
        }); 

对于你的下一个项目,我建议你使用类和命名空间来避免 1000 行文件; Ext.ns() 是您最好的 friend ,它将避免您遇到很多麻烦。

关于javascript - 如何在 Sencha touch 中滑动多个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8929322/

相关文章:

sencha-touch - Sencha Touch 密码

javascript - JSON.parse() 保持字符串编码

java - 如何使用 Java 序列化和反序列化来自 Google geocode 的 JSON 对象

sencha-touch - 如何在sencha touch中将图标对齐按钮的中心?

sencha-touch - 从 Sencha Touch 中的按钮触发 'tel' 链接

python - 将 json 字符串转换为 python 对象

SQL 查询中的 JavaScript 数组?

javascript - 使用 localStorage jQuery 删除单个 li

javascript - 我的 javascript 属性 window.innerWidth 没有提供我正在寻找的值?

javascript - 在 jQuery 中使用 $(this),如何修复?