1 | <!DOCTYPE HTML>
|
2 | <html>
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>Mock</title>
|
6 | <link href="assets/bootstrap/css/bootstrap.css" rel="stylesheet">
|
7 | <script type="text/javascript" src="http://a.tbcdn.cn/s/kissy/1.3.0/seed.js"></script>
|
8 |
|
9 | <script src="../dist/mock.js"></script>
|
10 | </head>
|
11 | <body>
|
12 | <div class="container">
|
13 | <h1>Mock 测试 - KISSY</h1>
|
14 | <h2>1. 设置模拟数据</h2>
|
15 | <pre id="data">
|
16 | Mock.mock('foo.json', {
|
17 | 'list|3-5':[{
|
18 | 'id|+1': 1,
|
19 | 'name': '@First @Last'
|
20 | }]
|
21 | });
|
22 | Mock.mock('bar.json', {
|
23 | 'list|3-5':[{
|
24 | 'id|+1': 100,
|
25 | 'email': '@EMAIL'
|
26 | }]
|
27 | });</pre>
|
28 | <h2>2. 发送请求</h2>
|
29 | <pre id="send">
|
30 | KISSY.use(['components/mock/index', 'core'], function(S, Mock, Core){
|
31 | var $ = S.all;
|
32 | KISSY.io({
|
33 | url:'foo.json',
|
34 | success: function(data){
|
35 | $('#foo').append(S.JSON.stringify(data, null, 4))
|
36 | }
|
37 | })
|
38 | KISSY.io({
|
39 | url:'bar.json',
|
40 | success: function(data){
|
41 | $('#bar').append(S.JSON.stringify(data, null, 4))
|
42 | }
|
43 | })
|
44 | });</pre>
|
45 | <h2>3. 响应数据</h2>
|
46 | <pre id="foo"></pre>
|
47 | <pre id="bar"></pre>
|
48 | </div>
|
49 | <script type="text/javascript">
|
50 | KISSY.use('core', function(S, Core) {
|
51 | var $ = S.all;
|
52 | eval( $('#data').text() )
|
53 | eval( $('#send').text() )
|
54 | })
|
55 | </script>
|
56 | </body>
|
57 | </html>
|