尝试在组合中使用 JSONStore
Trying to use JSONStore in a combo
在我们的应用程序中,我们有很多 name/value 商店,它们是在加载时创建的,并像这样放入 JSONStore 中:
Ext.create("Ext.data.JsonStore", {
data: data,
model: 'EM.model.controlUnit.CodeList',
storeId: "cl_" + tableId,
sorters: [{
sorterFn: aSorterFunction
}],
});
该模型非常简单,如下所示:
Ext.define('EM.model.controlUnit.CodeList', {
extend: 'Ext.data.Model',
fields: [{
name: 'value', type: 'int'
}, {
name: 'label', type: 'string'
}, {
name: 'description', type: 'string'
}]
});
我认为商店可以互换,所以我决定在组合中使用商店(没有特殊的组合商店所以我认为 JSONStore 一定和 SimpleStore 一样好).我是这样买的:
var msDataStore = Ext.getStore("cl_t_cl_maritalstatus");
并像这样使用商店:
{
xtype: 'combo',
fieldLabel: 'Marital Status',
displayField: "label",
valueField: "value",
store: msDataStore
}
当我 运行 应用程序时,组合被商店中的值填充,但是,当我弹出组合框时,抛出此错误:
ext-debug-w-comments.js:9951 Uncaught
Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have
not supplied it with a url.
我不需要任何服务器代理。这些是简单的本地存储名称值集合。
- JSONStores 可以与组合一起使用吗?
- 如果没有。将 JSONStore 转换为组合可接受的东西的最佳方法是什么。我可以砍掉、改变、重组商店对象。但我只是想知道在进行某种漫长而毫无意义的旅程之前,我是否可以做一些更简单的事情。
此问题与 'proxy' 属性 有关。 JsonStore 的默认代理是 'ajax';
proxy: {
type : 'ajax',
reader: 'json',
writer: 'json'
}
你应该像那样用 'memory' 覆盖;
proxy: {
type: 'memory'
}
您的最终商店是;
Ext.create("Ext.data.JsonStore", {
data: data,
model: 'EM.model.controlUnit.CodeList',
storeId: "cl_" + tableId,
proxy: {
type: 'memory'
}
sorters: [{
sorterFn: aSorterFunction
}],
});
没有URL的JsonStore
是完全可以接受的,但是你必须确保组合在点击下拉菜单时不会触发加载操作。这是通过向组合定义添加配置选项 queryMode:'local'
:
来完成的
{
xtype: 'combo',
fieldLabel: 'Marital Status',
displayField: "label",
valueField: "value",
queryMode: 'local',
store: msDataStore
}
在我们的应用程序中,我们有很多 name/value 商店,它们是在加载时创建的,并像这样放入 JSONStore 中:
Ext.create("Ext.data.JsonStore", {
data: data,
model: 'EM.model.controlUnit.CodeList',
storeId: "cl_" + tableId,
sorters: [{
sorterFn: aSorterFunction
}],
});
该模型非常简单,如下所示:
Ext.define('EM.model.controlUnit.CodeList', {
extend: 'Ext.data.Model',
fields: [{
name: 'value', type: 'int'
}, {
name: 'label', type: 'string'
}, {
name: 'description', type: 'string'
}]
});
我认为商店可以互换,所以我决定在组合中使用商店(没有特殊的组合商店所以我认为 JSONStore 一定和 SimpleStore 一样好).我是这样买的:
var msDataStore = Ext.getStore("cl_t_cl_maritalstatus");
并像这样使用商店:
{
xtype: 'combo',
fieldLabel: 'Marital Status',
displayField: "label",
valueField: "value",
store: msDataStore
}
当我 运行 应用程序时,组合被商店中的值填充,但是,当我弹出组合框时,抛出此错误:
ext-debug-w-comments.js:9951 Uncaught Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have not supplied it with a url.
我不需要任何服务器代理。这些是简单的本地存储名称值集合。
- JSONStores 可以与组合一起使用吗?
- 如果没有。将 JSONStore 转换为组合可接受的东西的最佳方法是什么。我可以砍掉、改变、重组商店对象。但我只是想知道在进行某种漫长而毫无意义的旅程之前,我是否可以做一些更简单的事情。
此问题与 'proxy' 属性 有关。 JsonStore 的默认代理是 'ajax';
proxy: { type : 'ajax', reader: 'json', writer: 'json' }
你应该像那样用 'memory' 覆盖;
proxy: { type: 'memory' }
您的最终商店是;
Ext.create("Ext.data.JsonStore", {
data: data,
model: 'EM.model.controlUnit.CodeList',
storeId: "cl_" + tableId,
proxy: {
type: 'memory'
}
sorters: [{
sorterFn: aSorterFunction
}],
});
没有URL的JsonStore
是完全可以接受的,但是你必须确保组合在点击下拉菜单时不会触发加载操作。这是通过向组合定义添加配置选项 queryMode:'local'
:
{
xtype: 'combo',
fieldLabel: 'Marital Status',
displayField: "label",
valueField: "value",
queryMode: 'local',
store: msDataStore
}