forked from alibaba/anyproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapList.js
More file actions
86 lines (75 loc) · 1.72 KB
/
mapList.js
File metadata and controls
86 lines (75 loc) · 1.72 KB
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
function fetchConfig(cb){
return $.getJSON("/getMapConfig",cb);
}
function init(React){
var MapList = React.createClass({
getInitialState:function(){
return {
ruleList : []
}
},
appendRecord:function(data){
var self = this,
newState = self.state.ruleList;
if(data && data.keyword && data.local){
newState.push({
keyword : data.keyword,
local : data.local
});
self.setState({
ruleList: newState
});
}
},
removeRecord:function(index){
var self = this,
newList = self.state.ruleList;
newList.splice(index,1);
self.setState({
ruleList : newList
});
},
render:function(){
var self = this,
collection = [];
collection = self.state.ruleList.map(function(item,index){
return (
<li>
<strong>{item.keyword}</strong><a className="removeBtn" href="#" onClick={self.removeRecord.bind(self,index)}>remove</a><br />
<span>{item.local}</span>
</li>
);
});
return (
<ul className="mapRuleList">
{collection}
</ul>
);
},
componentDidMount :function(){
var self = this;
fetchConfig(function(data){
self.setState({
ruleList : data
});
});
},
componentDidUpdate:function(){
var self = this;
//upload config to server
var currentList = self.state.ruleList;
$.ajax({
method : "POST",
url : "/setMapConfig",
contentType :"application/json",
data : JSON.stringify(currentList),
dataType : "json",
success :function(res){}
});
self.props.onChange && self.props.onChange(self.state.ruleList);
}
});
return MapList;
}
module.exports.init = init;
module.exports.fetchConfig = fetchConfig;