【问题标题】:Issue while Loading JSON with Store使用 Store 加载 JSON 时出现问题
【发布时间】:2012-10-09 09:15:24
【问题描述】:

我正在尝试从服务器获取一些 JSON 格式的主数据,并在 Store 的帮助下将其绑定到选择字段。

在下面找到我的代码

型号

Ext.define('Mobile.model.OrganizationModel', {
  extend: 'Ext.data.Model',
   config: {
    fields: [
        { name: 'Name', type: 'string' },
        { name: 'Id', type: 'int' }
    ]
   }
});

商店

Ext.define('Mobile.store.OrganizationStore', {
extend: 'Ext.data.Store',
model: 'Mobile.model.OrganizationModel',

autoLoad: true,

proxy: {
    type: 'ajax',
    url: 'login/GetOrgList',
    method: 'GET',
    reader: {
        type: 'json'
    }
}

});

查看

Ext.define("Mobile.view.LoginView", {
extend: "Ext.form.FormPanel",
alias: "widget.login",
id: 'loginFormPanel',

config: {

    margin: '0 auto',
    name: 'loginform',
    frame: true,
    url: 'login/Authenticate',
    title: 'something',
    items: [

      {
          xtype: 'fieldset',

          itemId: 'LoginFieldset',
          margin: '10 auto 0 auto ',

          title: '',
          items: [
                  {
                      xtype: 'selectfield',
                      label: 'Organization',
                      name: 'Organization',
                      store: 'OrganizationStore',
                      displayField: 'Name',
                      valueField: 'Id',
                      placeHolder: 'Select a Value'
                  }
            ]
      },


    ]
 }

});

APP.js

Ext.application({
name: "Mobile",   
controllers: ["LoginController"],
views: ['LoginView', 'HomeView'],
models: ['UserModel', 'OrganizationModel'],
stores: ['OrganizationStore'],
launch: function () {
    var loginPanel = Ext.create('Ext.Panel', {
        layout: 'fit',
        items: [
            {
                xtype: 'login'
            }
        ]
    });
    Ext.Viewport.add(loginPanel);
}

});

JSON数据格式

[{"Id":1,"Name":"公司 1"},{"Id":2,"Name":"公司 2"},{"Id":3,"Name":"公司 3"}]

问题是它没有向服务器发送请求并没有加载 JSON 数据和绑定。对这个问题有任何想法吗?

【问题讨论】:

    标签: sencha-touch extjs sencha-touch-2


    【解决方案1】:

    将您的存储代码更新为

        Ext.define('Mobile.store.OrganizationStore', {
    extend: 'Ext.data.Store',
    config:{
    model: 'Mobile.model.OrganizationModel',
    
    autoLoad: true,
    
    proxy: {
        type: 'ajax',
        url: 'login/GetOrgList',
        method: 'GET',
        reader: {
            type: 'json'
        }
    }
    
    
      }
      });
    

    【讨论】:

    • 谢谢。它对我有用。但是有必要保留配置部分吗?但文件docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-unmask 从未提及。您能否提供一些链接,我可以在其中引用来自服务器的负载并在本地进行编辑,然后在商店的帮助下更新回服务器。我正在寻找但不幸:(
    • 不要将 ExtJS 的文档用于 Sencha Touch :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    相关资源
    最近更新 更多