0

我只是在学习煎茶触摸 2,MVC。我会制作一个简单的表单来获取值,传递给 PHP 文件(用于对 Web 服务的 API 调用),移动到嵌套列表并显示结果。但是,我的应用程序在提交后没有显示任何内容......值被正确捕获(我在控制台日志中看到它)。请问有人可以帮我吗?

考虑测试一下,我现在不传递值,并且我的 API 调用直接使用硬编码值调用。将来我会努力传递表单价值......

先感谢您!

这是“app.js”

Ext.application({
  name:                     'Appre',
  icon:                     'resources/icons/icon.png',
  phoneStartupScreen:   'resources/images/phone_startup.png',
  //tabletStartupScreen: 'tablet_startup.png',
  glossOnIcon:          false,
  //profiles:           ['Phone', 'Tablet'],
  views :       ['Viewport','SearchCap','ElencoRistoranti'],
  models:           ['ElencoRistoranti'],
  stores:           ['RistorantiCap'],
  controllers:  ['SearchCap'],
  viewport: {
    layout: {
        type: 'card',
        animation: {
            type: 'slide',
            direction: 'left',
            duration: 300
        }
    }
},
launch: function() {
    Ext.create('Appre.view.Viewport')
} // launch: function() {
}) // Ext.application

这是表格“搜索帽”

Ext.define('Appre.view.SearchCap', {
extend: 'Ext.form.Panel',
xtype: 'appre-searchCap',
config: {
    items: [{
        xtype: 'fieldset',
        layout: 'vbox',
            items: [{
                xtype: 'textfield',
                name: 'cap',
                placeHolder: 'Cap' 
            },
            {
                xtype: 'button',
                text: 'Cerca',
                action :'searchCap',
                id:'btnSubmitLogin'
            }] // items
    }] // items
}, // config
initialize: function() {
    this.callParent(arguments);
    console.log('loginform:initialize');
}
});

这是控制器

Ext.define('Appre.controller.SearchCap', {
extend : "Ext.app.Controller",
config : {
    refs : {
        btnSubmitLogin: 'button[action=searchCap]',
        form : 'appre-searchCap'
    },
    control : {
        btnSubmitLogin : {
            tap : "onSubmitLogin"
        }
    }
},
onSubmitLogin : function() {
    console.log("onSubmitLogin");
    var values = this.getForm().getValues();
    console.log(values);
    var $this=this;
    Ext.Ajax.request({
        url: 'cerca-ristoranti-cap.php',
        method: 'POST',
        params: {
            values: Ext.encode({form_fields: values})
        },
        success: function(response, opts) {
            var obj = Ext.decode(response.responseText);
            //Ext.Msg.alert('Contact Complete!', obj.responseText);
            $this.resetForm();
            Ext.Viewport.add(Ext.create('Appre.view.ElencoRistoranti'));
            Ext.Viewport.setActiveItem(Ext.create('Appre.view.ElencoRistoranti'));
        },
        failure: function(response, opts) {
            console.log('server-side failure with status code ' + response.status);
        }
    });
},
resetForm: function() {
this.getForm().reset();
},
    launch : function() {
        this.callParent();
        console.log("LoginForm launch");
    },
    init : function() {
        this.callParent();
        console.log("LoginForm init");
    }
});

这是嵌套列表

Ext.define('Appre.view.ElencoRistoranti', {
extend: 'Ext.Panel',
xtype: 'appre-elencoristoranti',
config: {
    xtype: 'nestedlist',
    title: 'Cap',
    displayField: 'name',
    store: {
        type: 'tree',
        fields: [
            'id_restaurant', 'name',
            {name: 'leaf', defaultValue: true}
        ],
        root: {
            leaf: false
        },
        proxy: {
            type: 'ajax',
            url: 'cerca-ristoranti-cap.php',
            reader: {
                type: 'json',
                rootProperty: 'restaurants'
            } //reader
        } // proxy
    },
    detailCard: {
        xtype: 'panel',
        scrollable: true,
        styleHtmlContent: true
    },
    listeners: {
        itemtap: function(nestedList, list, index, element, post) {
            this.getDetailCard().setHtml(post.get('name'));
        }
    }
} // config
});

cerca-ristoranti-cap.php 它是一个简单的函数,它返回如下数组:

{
"restaurants":[{
    "id_restaurant":"40",
    "name":"La Saliera",
    "zip":"00128",
    "lat":"41.7900229",
    "lgt":"12.4513128"
}, {
    "id_restaurant":"64",
    "name":"Osteria del Borgo",
    "zip":"00128",
    "lat":"41.7887363",
    "lgt":"12.5149867"
}]

}

4

1 回答 1

1

嗨@sineverba 抱歉回复有点晚了,但这里有一些你想要展示的东西,

视口.js

Ext.define('myapp.view.Viewport' , {
  extend : 'Ext.viewport.Default',
  xtype : "viewport",
  config: {
    fullscreen: true,
    styleHtmlContent: true,
    style: 'background:#ffffff;',
    layout : 'card',
    autoDestroy : false,
    cardSwitchAnimation : 'slide',

    items: [
       {
          xtype: 'appre-searchCap'
       },
    ],
  }
})

应用程序.js

Ext.Loader.setConfig({
  enabled: true
})

Ext.application({
    name: 'myapp',
    requires: [
         'myapp.view.SearchCap',
         'myapp.view.ElencoRistoranti',
         'myapp.view.SearchElenco',
    ],
    controllers: ['SearchCap'],
    models: ['myapp.model.SearchCapModel'],
    launch: function() {
         Ext.create('myapp.view.Viewport')
    }
});

SearchCapModel.js

Ext.define('myapp.model.SearchCapModel', {
    extend: 'Ext.data.Model',
    config: {
         idProperty: 'id_restaurant',
         fields: [
             { name: 'id_restaurant', type: 'string' },
             { name: 'name', type: 'string'},
             { name: 'zip', type: 'string' },
             { name: 'lat', type: 'string'},
             { name: 'lgt', type: 'string'}
        ],
   }
})

SearchCapStore.js

Ext.define('myapp.store.SearchCapStore', {
    extend: 'Ext.data.Store',
    config: {
         model: 'myapp.model.SearchCapModel',
         autoLoad: true,
         proxy: {
             type: 'ajax',
             url : 'cerca-ristoranti-cap.json',
             reader: {
                   type: 'json',
                   rootProperty: 'restaurants'
             } //reader
         },
   }
});

SearchCap.js

Ext.define('myapp.controller.SearchCap', {
    extend : "Ext.app.Controller",

    views: ['SearchElenco'],

    config : {
         refs : {
             elencoListContainer: 'elencolistcontainer',
             btnSubmitLogin: 'button[action=searchCap]',
             form : 'appre-searchCap',
         },
         control : {
               btnSubmitLogin : {
                      tap : "onSubmitLogin"
               }
         }
    },
    onSubmitLogin : function() {
            console.log("onSubmitLogin");
            var values = this.getForm().getValues();
            console.log(values);

            Ext.Ajax.request({
                    url: 'cerca-ristoranti-cap.json',
                    method: 'POST',
                    params: {
                         values: Ext.encode({form_fields: values})
                    },
                    success: function(response, opts) {
                            var obj = response.responseText;
                            Ext.Msg.alert('Contact Complete!', obj);
                            Ext.Viewport.add(Ext.create('myapp.view.SearchElenco'));
                            Ext.Viewport.setActiveItem(1);
                    },
                    failure: function(response, opts) {
                          console.log('server-side failure with status code ' + response.status);
                    }
            });
    },
    resetForm: function() {
            this.getForm().reset();
    },
    launch : function() {
            this.callParent();
            console.log("LoginForm launch");
    },
    init : function() {
            this.callParent();
            console.log("LoginForm init");
    }
});

搜索Elenco.js

Ext.define('myapp.view.SearchElenco', {
    extend: 'Ext.Container',
    xtype: 'elencolistcontainer',

    requires: ['myapp.store.SearchCapStore'],

    initialize: function() {
            this.callParent(arguments);

            var s = Ext.create('myapp.store.SearchCapStore')
            var notesList = {
                    xtype: 'appre-elencoristoranti',
                    store: Ext.getStore(s).setAutoLoad(true),
                    listeners: {
                           disclose: {
                                    fn: this.onNotesListDisclose,
                                    scope: this
                           }
                    }
            };
            this.add([notesList])
    },
    onNotesListDisclose: function(list, record, target, index, event, options) {
            console.log('editNoteCommand');
            this.fireEvent('editNoteCommand', this, record);
    },

     config: {
           layout: {
                 type: 'fit'
           }
     }
});

ElencoRistoranti.js

Ext.define('myapp.view.ElencoRistoranti', {
    extend: 'Ext.dataview.List',
    xtype: 'appre-elencoristoranti',
    id: 'appreElenco',

    config: {
       emptyText: '<pre><div class="notes-list-empty-text">No list found.</div></pre>',
       onItemDisclosure: false,
       itemTpl: '<pre><div class="list-item-title">{id_restaurant}</div><div class="list-item-narrative">{name}</div></pre>',
    }
});

SearchCap.js - 查看

Ext.define('myapp.view.SearchCap', {
    extend: 'Ext.form.Panel',
    xtype: 'appre-searchCap',
    id: 'appreSearchCap',

    config: {
          layout: {
                type: 'vbox',
          },
          items: [
               {
                 xtype: 'fieldset',
                 title: 'Cap',
                 instructions: 'Enter Cap',
                 items: [
                     {
                        xtype: 'textfield',
                        name: 'cap',
                        placeHolder: 'Cap' 
                     },
                     {
                        xtype: 'button',
                        text: 'Cerca',
                        ui: 'confirm',
                        action :'searchCap',
                        id:'btnSubmitLogin'
                     }
                 ] // items
              }
         ] // items
    }, // config
    initialize: function() {
            this.callParent(arguments);
            console.log('loginform:initialize');
    }
});

在此处输入图像描述

希望对你有帮助,如果你有朋友请告诉我。:)

于 2012-07-26T21:26:13.447 回答