Extjs4.0学习笔记(c#.net页面生成json)

来源:互联网 发布:温州python培训班 编辑:程序博客网 时间:2024/06/05 13:34

extjs4.0的API上有无尽的讲法,无尽的例子,可是也没有给个.net的例子。怎样从数据库中取出数据形成json字符串然后进行绑定呢。

让我无尽纠结。不知所措的各种错误,各种工期临近。。。

Ext.onReady(function () {Ext.define('User', {    extend: 'Ext.data.Model',    fields: [            {type: 'string', name: 'abbr'},            {type: 'string', name: 'name'},            {type: 'string', name: 'slogan'}    ]});var myStore = Ext.create('Ext.data.Store', {    model: 'User',    proxy: {        type: 'ajax',        url : "Default2.aspx",//        reader: {//            type: 'json'//            ,root: 'users'//        }          reader:'json'    },    autoLoad: true});    // Simple ComboBox using the data store    var simpleCombo = Ext.create('Ext.form.field.ComboBox', {        fieldLabel: 'Select a single state',        renderTo: 'a',        displayField: 'name',        width: 320,        labelWidth: 130,        store: myStore,        queryMode: 'remote',// 实例大部分这里都是local,自己曾有过写成remove的经历o(╯□╰)o        typeAhead: true    });});
下面就开始有着无尽的烦恼了。。。先是搞错了json数据到底是单引号还是双引号,response后就报出json格式不对的各式错误。。。

后来干脆直接将Default2.aspx所有的东西都删掉了,然后在上面赤裸裸的写上了json串,竟然好用(这已经纠结了三天了,始终不知道该怎么改,或者处理)

        string a = "[{\"abbr\":\"AL\",\"name\":\"Alabama\",\"slogan\":\"The Heart of Dixie\"},{\"abbr\":\"WI\",\"name\":\"Wisconsin\",\"slogan\":\"Americas Dairyland\"}]";        Response.Write(a);        Response.End();//就这一句话,让我。。。

继续向前向前。
//        reader: {//            type: 'json'//            ,root: 'users'//        }

这里之所以注释了是因为我直接将Default2.aspx写成

"users": [{"abbr":"AL","name":"Alabama","slogan":"The Heart of Dixie"},{"abbr":"WI","name":"Wisconsin","slogan":"Americas Dairyland"}]

或者

"success": true,"users":[{"abbr":"AL","name":"Alabama","slogan":"The Heart of Dixie"},{"abbr":"WI","name":"Wisconsin","slogan":"Americas Dairyland"}]

都不成。求指教。。。。

原创粉丝点击