代码片段(1)[全屏查看所有代码]
1. [文件] EXTJS组件省市联动_修改.js.js ~ 7KB 下载(131)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
/**
* 省市的联动(数据从字典表中取得)
*/
Ext.namespace(
'Ext.form.dict'
);
Ext.form.dict.provSelector = Ext.extend(Ext.form.CompositeField, {
id:
""
,
configs:{},
constructor:
function
(config) {
configs = config ;
if
(Ext.isArray(config)) {
config = {items:config};
configs = config ;
}
//alert(Ext.encode(configs));
id = configs.id;
//省份数据
var
storeProvince = DictStore.getDictStore(DICTCODE.CODE_PROVINCE);
//省
var
provList =
this
.storeToArray(storeProvince);
//北京市数据
var
storeCity = DictStore.getDictStore(DICTCODE.CODE_COUNTY);
var
cityList =
this
.storeToArray(storeCity);
//外省市
var
cityListOther =[{
'name'
:
'请选择'
,
'pinyin'
:
''
,
'value'
:
''
},{
'name'
:
'外省市'
,
'pinyin'
:
'WSS'
,
'value'
:
'1000'
}];
//国外
var
cityListForeign = [{
'name'
:
'请选择'
,
'pinyin'
:
''
,
'value'
:
''
}, {
'name'
:
'国外'
,
'pinyin'
:
'GW'
,
'value'
:
'2000'
}];
//区县数据
var
cityStore =
new
Ext.data.Store({
proxy:
new
Ext.data.MemoryProxy(),
reader:
new
Ext.data.JsonReader(
{root:
''
},
[{name:
'name'
},
{name:
'pinyin'
},
{name:
'value'
}
])
});
//区县
var
cityCombo =
new
Ext.form.ComboBox({
store: cityStore,
typeAhead:
true
,
mode:
'local'
,
id : configs.cityComboID,
name : configs.cityComboID,
allowBlank: configs.allowBlank,
emptyText:
'请选择'
,
triggerAction:
'all'
,
hiddenName:
'hidden'
+ configs.cityComboID,
valueField:
'value'
,
displayField:
'name'
,
width: 120,
editable:
false
,
anchor :
'100%'
,
listeners:{
change :
function
(combo, record, index) {
},
beforeselect :
function
(combo, record, index) {
//详细地址
Ext.getCmp(configs.detailAddressID).setValue(
""
);
},
afterrender :
function
(comb, record, index) {
}
}
});
//省数据
var
provStore =
new
Ext.data.Store({
proxy:
new
Ext.data.MemoryProxy(provList),
reader:
new
Ext.data.JsonReader(
{root:
''
},
[{name:
'name'
},
{name:
'pinyin'
},
{name:
'value'
}
])
});
provStore.load();
//省
var
provCombo =
new
Ext.form.ComboBox({
store: provStore,
typeAhead:
true
,
mode:
'local'
,
id : configs.provComboID,
name : configs.provComboID,
allowBlank: configs.allowBlank,
emptyText:
'请选择'
,
triggerAction:
'all'
,
hiddenName:
'hidden'
+ configs.provComboID,
valueField:
'value'
,
displayField:
'name'
,
width: 120,
editable:
false
,
anchor :
'100%'
,
listeners:{
beforeselect :
function
(combo, record, index){
cityCombo.setValue(
""
);
if
(record.data.value ==
'1'
) {
eval(
"cityCombo.store.proxy = new Ext.data.MemoryProxy(cityList);"
);
}
else
if
(record.data.value ==
'2000'
){
eval(
"cityCombo.store.proxy = new Ext.data.MemoryProxy(cityListForeign);"
);
}
else
{
eval(
"cityCombo.store.proxy = new Ext.data.MemoryProxy(cityListOther);"
);
}
cityCombo.store.load();
//详细地址
Ext.getCmp(configs.detailAddressID).setValue(
""
);
},
afterrender :
function
(comb, record, index) {
}
}
});
//详细地址
var
detailAddress =
new
Ext.form.TextField({
id: configs.detailAddressID,
name : configs.detailAddressID,
xtype:
'textfield'
,
emptyText:
'详细地址'
,
width: 363,
allowBlank: configs.allowBlank
});
Ext.apply(
this
, config, {
fieldLabel:configs.fieldLabel,
items: [
provCombo, cityCombo, detailAddress
]
});
//自定数据的取得
this
.provArray = provList;
this
.cityArray = cityList;
this
.provCombo = provCombo;
this
.cityCombo = cityCombo;
this
.detailAddress = detailAddress;
Ext.form.dict.provSelector.superclass.constructor.call(
this
);
},
/**
* 将Ext.Json.Store对象
* 数组对象
* 转换成Json形式的数组
* @param {} store
* @return {}
*/
storeToArray:
function
(jsondata){
var
listRecord;
if
(jsondata
instanceof
Ext.data.Store){
listRecord =
new
Array();
jsondata.each(
function
(record){
listRecord.push(record.data);
});
}
else
if
(jsondata
instanceof
Array){
listRecord =
new
Array();
Ext.each(jsondata,
function
(record){
listRecord.push(record.data);
});
}
return
listRecord;
},
/**
* 取得下拉列表的值所对应的名称
*/
getArrayDefaultName :
function
(provValue, valueArray) {
var
defaultValueName =
""
;
for
(
var
i= 0; i<valueArray.length; i++) {
var
record = valueArray[i];
if
(provValue == record[
"value"
]) {
defaultValueName = record[
"name"
];
break
;
}
}
return
defaultValueName;
},
setValue :
function
(value) {
//省的值
var
provValue = value[configs.provComboID];
var
provName =
""
;
//市的值
var
cityValue = value[configs.cityComboID];
var
cityName =
""
;
//省
var
_provArray =
this
.provArray;
provName =
this
.getArrayDefaultName(provValue, _provArray);
this
.provCombo.setValue(provValue);
//隐藏的值
this
.provCombo.setRawValue(provName);
//显示的内容
//市的选择
if
(provValue ==
"1"
) {
//市
var
_cityArray =
this
.cityArray;
cityName =
this
.getArrayDefaultName(cityValue, _cityArray);
this
.cityCombo.setValue(
""
);
eval(
"this.cityCombo.store.proxy = new Ext.data.MemoryProxy(_cityArray);"
);
this
.cityCombo.store.load();
this
.cityCombo.setValue(cityValue);
//隐藏的值
this
.cityCombo.setRawValue(cityName);
//显示的内容
}
else
if
(provValue ==
"2000"
) {
//国外
this
.cityCombo.setValue(provValue);
//隐藏的值
this
.cityCombo.setRawValue(
"国外"
);
//显示的内容
}
else
{
//外省市
this
.cityCombo.setValue(
"1000"
);
//隐藏的值
this
.cityCombo.setRawValue(
"外省市"
);
//显示的内容
}
//详细地址的赋值
Ext.getCmp(configs.detailAddressID).setValue(value[configs.detailAddressID]);
}
});
Ext.reg(
'provSelector'
, Ext.form.dict.provSelector);
|