-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataSource.jsx
More file actions
58 lines (51 loc) · 1.33 KB
/
dataSource.jsx
File metadata and controls
58 lines (51 loc) · 1.33 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
'use strict'
import React from 'react'
import prettify from '../prettify'
@prettify
export default class Page extends React.Component {
static displayName = 'Pages/DataSource'
render () {
return (
<div>
<div className="header">
<h1>dataSource</h1>
<h2>数据接口</h2>
</div>
<div className="content">
<p>Select, Tree 等控件需要从服务器远程获取数据的接口。</p>
<p>接口返回一个方法,<em>then</em>成功回调,<em>catch</em>失败回调,<em>complete</em>成功与失败都会调用</p>
<p>ReactUI内部提供了一个dataSource,使用Qwest实现的,可以用其他的Ajax框架自行实现。</p>
<pre className="prettyprint">
{`function (src, data, options) {
let stacks = {
'then': [],
'catch': [],
'complete': []
},
promises = ['then', 'catch', 'complete'],
req = null,
qwest = function () {
req = Qwest.get(src, data, options)
promises.forEach(p => {
req[p](res => {
stacks[p].forEach(func => {
func(res)
})
})
})
return qwest
}
promises.forEach(p => {
qwest[p] = func => {
stacks[p].push(func)
return qwest
}
})
return qwest
}`}
</pre>
</div>
</div>
)
}
}