ExtJS组合框jsonDataStore

时间:2009-09-23 12:58:59

标签: json extjs ashx

var remoteLookupJsonStore = new Ext.data.JsonStore({
root : 'records',
baseParams : {
  column : 'fullName'
},
fields : [
{
  name : 'name',
  mapping : 'fullName'
},
{
  name : 'id',
  mapping : 'id'
}
],
proxy : new Ext.data.ScriptTagProxy({
    url : 'LookupLoader.ashx'
     //url: 'http://tdg-i.com/dataQuery.php' similar data
})
});

var combo2 = {
xtype : 'combo',
fieldLabel : 'Search by name',
forceSelection : true,
displayField : 'name',
valueField : 'id',
hiddenName : 'customerId',
loadingText : 'Querying....',
minChars : 1,
triggerAction : 'name',
store : remoteLookupJsonStore
};

此示例适用于原始数据存储“http://tdg-i.com/dataQuery.php”。我的ashx处理程序以相同的格式返回数据,但数据不同。无论如何,当我使用我的ashx处理程序时,处理程序被调用,它返回数据,但是组合总是保持在加载状态,并且从不显示数据。 我假设问题是我返回的数据,但它的格式很好,我改变的最后一件事是设置内容类型

context.Response.ContentType =“application / json”;

但我仍然无法让这件事工作,有什么建议吗?

这是来自我的处理程序的数据。

({“totalCount”:“4”,“records”:[{“id”:1,“fullName”:“aaa bbb”},{“id”:2,“fullName”:“cc dd” },{“id”:3,“fullName”:“ee ff”},{“id”:4,“fullName”:“gg hh”}]});

2 个答案:

答案 0 :(得分:0)

你的第一条记录(id 1)缺少“fullName”,这使得JSON无效 - 不确定这是否只是在这里输入错误。

答案 1 :(得分:0)

proxy : new Ext.data.ScriptTagProxy({
    url : 'LookupLoader.ashx'
     //url: 'http://tdg-i.com/dataQuery.php' similar data
})

好像查询相同的域名,我应该使用 HttpProxy

所以你有它,这就是为什么它使用网站提供的样本数据而不是我的本地版本。