ExtJS:如何在另一个函数中调用一个函数?
ExtJS: How to call a function within another function?
我知道有很多关于在另一个函数中调用一个函数的问题,但不幸的是 none 对我有用,或者我无法实现我的项目!
我有一个Window
class,里面说了两个函数。第二个是通过 combobox
获取带有 ID 的特定 URL 并返回它。我需要在第一个 function
;
中使用这个生成的 URL
getSelectCountry: function(){
var countryRecord = Ext.ComponentQuery.query('[name=country]')[0].getSelectedRecord();
var countryId = countryRecord.get('id');
var urlWithId = MyApp.Globals.getUrl() + '/city/view/list/?countryid='+ countryId;
// var store = Ext.getStore('cityCombo');
// store.load({
// url : MyApp.Globals.getUrl() + '/city/view/list/?countryid='+ countryId,
// });
return urlWithId;
}
我需要在 citycombo
的 proxy
的 url
中使用下面返回的 urlWithId
。它会根据以下国家/地区列出城市;
Ext.define('MyApp.view.weather.SettingsWindow', {
...
getSettingsItems: function () {
var me = this;
var settingsItems = [
{
xtype: 'form',
layout: {type: 'vbox', align: 'stretch', pack: 'start'},
reference: 'settingsForm',
items: [
{
xtype: 'citycombo',
itemId: 'cityName',
name: 'city',
afterLabelTextTpl: MyApp.Globals.required,
allowBlank: false,
flex: 1,
store: {
storeId: 'cityCombo',
proxy: {
type: 'ajax',
// I neeed returned URL with ID on here.
url: MyApp.Globals.getUrl() + '/city/view/list/',
reader: {
type: 'json',
rootProperty: 'data'
}
},
pageSize: 0,
sorters: 'description',
autoLoad: true
}
},
我试过使用 store.load
或创建一个新变量并调用它,但我无法成功。
我很乐意提供任何想法。
更新
- 请检查这些屏幕截图:UI and code structure
- 我正在尝试获取由
getSelectCountry
函数 (1) 生成的完整 URL
并使用 citycombo
过滤城市查询这个新返回 URL (2).
如果只关心那个小参数,那么您真正想要做的是在商店的 beforeload 侦听器中填充 extraParams
属性。
listeners: {
beforeload: function(store) {
// Get countryRecord from somewhere...
store.getProxy().setExtraParams("countryid", countryRecord.get('id'))
}
如果server/pathname也不同,也可以setUrl()
.
相关fiddle:https://fiddle.sencha.com/#view/editor&fiddle/2c8a
更新:
所以,你真正想做的是:
xtype: 'combobox',
queryMode: 'local',
fieldLabel: 'Country',
store: ...,
listeners: {
select: function(combo, countryRecord) {
var cityStore = combo.nextSibling().getStore();
cityStore.getProxy().setExtraParam('countryId', countryRecord.get('Id'));
cityStore.load();
}
},
},{
xtype: 'combobox',
queryMode: 'local',
fieldLabel: 'City',
store: ...,
我看到两种可能性:
- 扩展 亚历山大的 解决方案。假设
cityCombo
定义了 beforeload 回调设置 url
或 extraparams
,您在 country
组合框上定义一个 change
侦听器,并调用 cityCombo's
load()
从那里。
见下文:
listeners: {
change: function () {
Ext.getStore('cityCombo')
.load()
}
}
或者更好的是,从商店中删除 beforeload
并将其中的内容放入第一个 combobox
的 change
中
listeners: {
change: function (combo, newValue) {
var cityStore = Ext.getStore('cityCombo')
cityStore.getProxy()
.setUrl(getSelectedCountry());
cityStore.load();
}
}
注意:您可以进一步重构它,摆脱 getSelectedCountry()
并在侦听器传递的组合上完成所有操作
- 在
cityCombo
上使用过滤器而不是往返
编辑:修复了第一个代码块的显示,添加了缺少的 load()
调用。
我知道有很多关于在另一个函数中调用一个函数的问题,但不幸的是 none 对我有用,或者我无法实现我的项目!
我有一个Window
class,里面说了两个函数。第二个是通过 combobox
获取带有 ID 的特定 URL 并返回它。我需要在第一个 function
;
URL
getSelectCountry: function(){
var countryRecord = Ext.ComponentQuery.query('[name=country]')[0].getSelectedRecord();
var countryId = countryRecord.get('id');
var urlWithId = MyApp.Globals.getUrl() + '/city/view/list/?countryid='+ countryId;
// var store = Ext.getStore('cityCombo');
// store.load({
// url : MyApp.Globals.getUrl() + '/city/view/list/?countryid='+ countryId,
// });
return urlWithId;
}
我需要在 citycombo
的 proxy
的 url
中使用下面返回的 urlWithId
。它会根据以下国家/地区列出城市;
Ext.define('MyApp.view.weather.SettingsWindow', {
...
getSettingsItems: function () {
var me = this;
var settingsItems = [
{
xtype: 'form',
layout: {type: 'vbox', align: 'stretch', pack: 'start'},
reference: 'settingsForm',
items: [
{
xtype: 'citycombo',
itemId: 'cityName',
name: 'city',
afterLabelTextTpl: MyApp.Globals.required,
allowBlank: false,
flex: 1,
store: {
storeId: 'cityCombo',
proxy: {
type: 'ajax',
// I neeed returned URL with ID on here.
url: MyApp.Globals.getUrl() + '/city/view/list/',
reader: {
type: 'json',
rootProperty: 'data'
}
},
pageSize: 0,
sorters: 'description',
autoLoad: true
}
},
我试过使用 store.load
或创建一个新变量并调用它,但我无法成功。
我很乐意提供任何想法。
更新
- 请检查这些屏幕截图:UI and code structure
- 我正在尝试获取由
getSelectCountry
函数 (1) 生成的完整URL
并使用citycombo
过滤城市查询这个新返回 URL (2).
如果只关心那个小参数,那么您真正想要做的是在商店的 beforeload 侦听器中填充 extraParams
属性。
listeners: {
beforeload: function(store) {
// Get countryRecord from somewhere...
store.getProxy().setExtraParams("countryid", countryRecord.get('id'))
}
如果server/pathname也不同,也可以setUrl()
.
相关fiddle:https://fiddle.sencha.com/#view/editor&fiddle/2c8a
更新:
所以,你真正想做的是:
xtype: 'combobox',
queryMode: 'local',
fieldLabel: 'Country',
store: ...,
listeners: {
select: function(combo, countryRecord) {
var cityStore = combo.nextSibling().getStore();
cityStore.getProxy().setExtraParam('countryId', countryRecord.get('Id'));
cityStore.load();
}
},
},{
xtype: 'combobox',
queryMode: 'local',
fieldLabel: 'City',
store: ...,
我看到两种可能性:
- 扩展 亚历山大的 解决方案。假设
cityCombo
定义了 beforeload 回调设置url
或extraparams
,您在country
组合框上定义一个change
侦听器,并调用cityCombo's
load()
从那里。
见下文:
listeners: {
change: function () {
Ext.getStore('cityCombo')
.load()
}
}
或者更好的是,从商店中删除 beforeload
并将其中的内容放入第一个 combobox
change
中
listeners: {
change: function (combo, newValue) {
var cityStore = Ext.getStore('cityCombo')
cityStore.getProxy()
.setUrl(getSelectedCountry());
cityStore.load();
}
}
注意:您可以进一步重构它,摆脱 getSelectedCountry()
并在侦听器传递的组合上完成所有操作
- 在
cityCombo
上使用过滤器而不是往返
编辑:修复了第一个代码块的显示,添加了缺少的 load()
调用。