码迷,mamicode.com
首页 > Web开发 > 详细

ExtJS 4 【Ext.data.proxy.Ajax】

时间:2016-11-30 21:50:03      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:return   operation   host   back   cal   hostname   new   url   color   

namespace ExtJSProject.WebApi.Models
{
    [Serializable]
    [DataContract]
    public class Person
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public int Age { get; set; }
    }
}

 

namespace ExtJSProject.WebApi.Controllers
{
    [RoutePrefix("api/Person")]
    public class PersonController : ApiController
    {
        [HttpGet]
        public List<Models.Person> Get(int page, int start, int limit)
        {
            return new List<Models.Person>()
            {
                new Models.Person() {Name="张三",Age=25 },
                new Models.Person() {Name="李四",Age=25 }
            };
        }
    }
}

 

var baseUrl = "http://" + window.location.hostname + "/ExtJS.WebApi/api/";
Ext.onReady(function () {

    Ext.define("Person", {
        extend: ‘Ext.data.Model‘,
        fields: [‘Name‘, ‘Age‘]
    });

    var ajaxProxy = new Ext.data.proxy.Ajax({
        url: baseUrl + ‘Person/Get‘,
        model: ‘Person‘,
        reader: ‘json‘
    });
    var operation = new Ext.data.Operation({
        action: ‘read‘,
        page: 2,
        start: 50,
        limit: 25
    });
    ajaxProxy.doRequest(operation, callBack);
    function callBack(operation) {
        console.log(operation.response.responseText);    //[{"Name":"张三","Age":25},{"Name":"李四","Age":25}]   
    }

});

ExtJS 4 【Ext.data.proxy.Ajax】

标签:return   operation   host   back   cal   hostname   new   url   color   

原文地址:http://www.cnblogs.com/CodingArt/p/6119647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!