PDA

View Full Version : Problems configuring a remote real-time search



BillySao
30 Jan 2014, 2:17 PM
I am setting up a store for remote real-time search with ashx service "Net." But does not work me, this is the code of the store:




Ext.define('App.store.list', {
extend: 'Ext.data.Store',

requires: [
'App.model.MyModel'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
model: 'App.model.MyModel',
storeId: 'MyJsonStore',
proxy: {
type: 'ajax',
url: '../Service/cargarListaMaestro.ashx',
reader: {
type: 'json',
root: 'Client',
totalProperty: 'totalCount'
}
}
}, cfg)]);
}
});



This is my model:




Ext.define('App.model.MyModel', {
extend: 'Ext.data.Model',


idProperty: 'CodigoCliente',


fields: [
{
name: 'CodigoCliente',
type: 'int'
},
{
name: 'Empresa',
type: 'string'
},
{
name: 'CodigoEmpresa',
type: 'string'
}
]
});



This is the service code ashx:



using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;


namespace Sas.Sao.Ventas.UI.Web.Servicios
{
/// <summary>
/// Summary description for cargarListaMaestro
/// </summary>
public class cargarListaMaestro : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{

var serializer = new JavaScriptSerializer();
Sas.Sao.Ventas.UI.Web.DataAccess.daClientesDataContext data;

string prefixText = string.Empty;
context.Response.ContentType = "application/json";
try
{
if (!string.IsNullOrEmpty(context.Request["query"]))
{
prefixText = context.Request["query"];
}

data = new Sas.Sao.Ventas.UI.Web.DataAccess.daClientesDataContext();

List<Clientes> cliente = new List<Clientes> (
from si in data.Clientes
where si.CodigoCliente.ToString().Contains(prefixText.ToUpper())
|| si.Empresa.ToString().Contains(prefixText.ToUpper())

select new Clientes
{
IdCliente = si.IdCliente,
CodigoCliente = si.CodigoCliente.ToString(),
Empresa = si.Empresa,
CodigoEmpresa = String.Format("{0}, {1}", si.CodigoCliente, si.Empresa),

}).Take(10).AsEnumerable().ToList();

context.Response.Write(string.Format("{{totalCount:{1},'Client':{0}}}", serializer.Serialize(cliente), cliente.Count));

}
catch (Exception ex)
{
string m = ex.Message;
}


}


public bool IsReusable
{
get
{
return false;
}
}
}
}



Here's the code of the class:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


namespace UI.Web
{
public class Clientes
{
public String CodigoCliente { get; set; }


public String Empresa { get; set; }


public String CodigoEmpresa { get; set; }


public Int32 IdCliente { get; set; }
}
}


This is the error when trying to load the store and will not let me search in real time on a "comboBox":



Uncaught TypeError: Converting circular structure to JSON
Source Class: ionp:/src/frameworks/ext42/ext-overrides.js?0.012853628490120173 Line 177