ITPub博客

首页 > > > extjs 取数据问题

extjs 取数据问题

作者:ofan 时间:2019-09-03 10:25:59 0 删除 编辑

版本3.0

后台代码:

public JsonResult City()

{

returnJson("{\"data\":[{\"id\":1,\"name\":\"北京\"}]}", JsonRequestBehavior.AllowGet);

}

js:

Ext.onReady(function () {
        //创建市数据源
        var combocitystore = new Ext.data.Store({
            //设定读取的地址
            proxy: new Ext.data.HttpProxy({ url: 'combobox/City' }),
            //设定读取的格式    
            reader: new Ext.data.JsonReader({ root: 'data' }, [
            { name: "id" },
            { name: "name"}])
        });

        //创建市Combobox
        var comboboxcity = new Ext.form.ComboBox({
            id: 'comboboxcity',
            fieldLabel: '市',
            width: 120,
            store: combocitystore,
            displayField: 'name',
            valueField: 'id',
            triggerAction: 'all',
            emptyText: '请选择...',
            allowBlank: false,
            blankText: '请选择市',
            editable: false,
            mode: 'local', //该属性和以下方法为了兼容ie8
            listeners: {
                'render': function () {
                    combocitystore.load();
                    alert(combocitystore.getCount());
                }
            }
        });

        //----------------------下拉列表结束----------------------//
        //表单
        var form = new Ext.form.FormPanel({
            frame: true,
            title: '表单标题',
            style: 'margin:10px',
            items: [comboboxcity, comboareacity]
        });
        //窗体
        var win = new Ext.Window({
            title: '窗口',
            width: 476,
            height: 374,
            resizable: true,
            modal: true,
            closable: true,
            maximizable: true,
            minimizable: true,
            buttonAlign: 'center',
            items: form
        });
        win.show();
 ---自己写的ajax是正常的
        $.ajax({

            type: "post",
            url: 'combobox/City',
            data: null,
            dataType: "json",
            success: function (data) {
                var d = $.parseJSON(data);
            }

        });
    });

原因combocitystore 为null 是什么原因呢?

脚本无错误

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4571/viewspace-3168951/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-01

  • 博文量
    159
  • 访问量
    1161