MCPcopy Create free account
hub / github.com/Lobos/react-ui / render

Method render

docs/src/js/pages/dataSource.jsx:7–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5
6module.exports = class extends React.Component {
7 render () {
8 return (
9 <div>
10 <div className="header">
11 <h1>dataSource</h1>
12 <h2>数据接口</h2>
13 </div>
14
15 <div className="content">
16 <h3 style={{color: 'red'}}>下个版本将废除,改用highorder compontent</h3>
17 <p>Select, Tree 等控件需要从服务器远程获取数据的接口。</p>
18 <p>接口返回一个方法,<em>then</em>成功回调,<em>catch</em>失败回调,<em>complete</em>成功与失败都会调用</p>
19 <p>ReactUI内部提供了一个dataSource,使用Qwest实现的,可以用其他的Ajax框架自行实现。</p>
20 <Code>
21{`function (src, data, options) {
22 let stacks = {
23 'then': [],
24 'catch': [],
25 'complete': []
26 },
27 promises = ['then', 'catch', 'complete'],
28 req = null,
29
30 qwest = function () {
31 req = Qwest.get(src, data, options)
32 promises.forEach(p => {
33 req[p](res => {
34 stacks[p].forEach(func => {
35 func(res)
36 })
37 })
38 })
39 return qwest
40 }
41
42 promises.forEach(p => {
43 qwest[p] = func => {
44 stacks[p].push(func)
45 return qwest
46 }
47 })
48
49 return qwest
50}`}
51 </Code>
52 </div>
53 </div>
54 );
55 }
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected