-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.vue
113 lines (108 loc) · 2.89 KB
/
App.vue
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
<template>
<div>
<div class="dx-fieldset" style="width:50%">
<div class="dx-fieldset-header">Select State, City</div>
<div class="dx-field">
<div class="dx-field-label">State</div>
<div class="dx-field-value">
<DxSelectBox
:data-source="states"
value-expr="ID"
display-expr="Name"
@valueChanged="stateValueChanged"
/>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">City</div>
<div class="dx-field-value">
<DxSelectBox
:ref="citySelectBoxRefKey"
:data-source="cities"
:value.sync="cityValue"
value-expr="ID"
display-expr="Name"
/>
</div>
</div>
<div class="dx-fieldset-header">In Form</div>
<div class="dx-field">
<DxForm :form-data.sync="address" @field-data-changed="fieldDataChanged">
<DxSimpleItem
data-field="StateID"
editor-type="dxSelectBox"
:editor-options="stateEditorOptions"
>
<DxLabel text="State"></DxLabel>
</DxSimpleItem>
<DxSimpleItem
data-field="CityID"
editor-type="dxSelectBox"
:editor-options="cityEditorOptions"
>
<DxLabel text="City"></DxLabel>
</DxSimpleItem>
</DxForm>
</div>
</div>
</div>
</template>
<script>
import { DxSelectBox } from "devextreme-vue";
import DxForm, { DxSimpleItem, DxLabel } from "devextreme-vue/form";
import service from "./data.js";
const citySelectBoxRefKey = "city-select-box";
export default {
components: {
DxSelectBox,
DxForm,
DxSimpleItem,
DxLabel
},
data() {
const states = service.getStates(),
cities = service.getCities();
return {
states,
cities,
cityValue: null,
citySelectBoxRefKey,
address: service.getAddress(),
stateEditorOptions: {
dataSource: states,
valueExpr: "ID",
displayExpr: "Name"
},
cityEditorOptions: {
dataSource: cities,
valueExpr: "ID",
displayExpr: "Name"
}
};
},
methods: {
stateValueChanged: function(e) {
this.cityDataSource.filter(["StateID", "=", e.value]);
this.cityDataSource.load();
this.cityValue = null;
},
fieldDataChanged: function(e) {
if (e.dataField === "StateID") {
var cityEditor = e.component.getEditor("CityID");
let dataSource = cityEditor.getDataSource();
dataSource.filter(["StateID", "=", e.value]);
dataSource.load();
this.address.CityID = null;
}
}
},
computed: {
citySelectBox: function() {
return this.$refs[citySelectBoxRefKey].instance;
},
cityDataSource: function() {
return this.citySelectBox.getDataSource();
}
}
};
</script>