Search code examples
javascriptextjssencha-touchsencha-touch-2extjs4.1

How to make EXT JS model and proxy store work? (please_help!)


I hav'nt understood how to link server data and form's field by using REST api.

I have form with some selectfields. And i have values for this particularly fields on server. I think that forms can get data from store trought model (y/n?). If it is true i have a question: how to add exist forms to model? So main target - get values from server to the exist selectfields of exist form trought REST API.

Here is what I have now: -proxy store:

Ext.define('Foresto.store.RESTstore',{ 
extend: 'Ext.data.Store',
storeID:'reststore',
proxy: {
    type:'rest',
    url:'http://localhost:6666/api/form',
    reader:{
        type: 'json',
        root: ''
    }
},
autoLoad: true});

-one from forms:

Ext.define('Foresto.view.forms.Cutarea', {
extend: 'Ext.form.Panel',
title: 'ForestoL',
header: {
    cls: 'header-cls',

},
scrollable: true,
xtype: 'forestoL',

url: 'save-form.php',

items: [{
    xtype: 'selectfield',
    label: 'Field1',
    name: 'name'
},{
    xtype: 'selectfield',
    label: 'Field2',
    name: 'allotment'
}] ...

Please hepl! Thanks, Artur.


Solution

  • See this fiddle of a basic remote combobox.

    {
        xtype: 'combo',
        fieldLabel: 'My Combo',
        valueField: 'id',
        displayField: 'title',
        anchor: '100%',
        store: new Ext.data.Store({
            autoLoad: true,
            fields: ['id', 'title'],
            proxy: {
                type: 'ajax',
                url: 'records.json'
            }
        })
    }