-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1473 lines (1419 loc) · 64.4 KB
/
index.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mock.js</title>
<meta name="keywords" content="模拟数据生成器,模拟数据,模拟请求,Simulation Data Generator" />
<link rel="icon" href="/favicon.ico">
<link href="./demo/assets/bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
font: 14px/1.7 'helvetica neue', 'hiragino sans gb', stheiti,'wenquanyi micro hei',\5FAE\8F6F\96C5\9ED1,\5B8B\4F53, sans-serif;
}
.page-catalog > ul {
padding-left: 0px;
}
.page-catalog ul {
padding-left: 20px;
/*list-style: none;*/
}
.gist .gist-file .gist-data .line-numbers {
line-height: 20px;
}
.gist .gist-file .gist-data .line-data {
line-height: 20px;
}
/* Backbone.js */
div#sidebar {
background: #fff;
position: fixed;
z-index: 10;
top: 0; left: 0; bottom: 0;
width: 220px;
overflow-y: auto;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
padding: 15px 0 30px 30px;
border-right: 1px solid #bbb;
box-shadow: 0 0 20px #ccc; -webkit-box-shadow: 0 0 20px #ccc; -moz-box-shadow: 0 0 20px #ccc;
}
div.container {
position: relative;
width: 700px;
margin: 40px 0 50px 280px;
padding-right: 40px;
}
/* download */
.w250 {
width: 250px;
}
/* header */
h1, h2, h3 {
margin-top: 20px;
margin-bottom: 10px;
}
h4, h5, h6 {
margin-top: 20px;
margin-bottom: 10px;
}
</style>
<style type="text/css">
@font-face {
font-family: 'logo';
src: url('http://at.alicdn.com/t/font_1390195988_9420388.eot'); /* IE9*/
src: url('http://at.alicdn.com/t/font_1390195988_9420388.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('http://at.alicdn.com/t/font_1390195989_0386753.woff') format('woff'), /* chrome、firefox */
url('http://at.alicdn.com/t/font_1390195988_7969282.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
url('http://at.alicdn.com/t/font_1390195989_0668917.svg#svgFontName') format('svg'); /* iOS 4.1- */
}
.iconlogo {
font-family: "logo";
font-size: 60px;
font-style: normal;
font-weight: normal;
font-variant: normal;
display: inline-block;
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #08C;
}
</style>
</head>
<body>
<div id="sidebar" class="interface"></div>
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./dist/mock.js"></script>
<div class="container"><!-- ## Mock.js -->
<p><h2 class="hide" href="#">Mock.js</h2>
<img class="hide" src="mockjs.png" wid></p>
<h1 style="color: #428BCA; margin-bottom: 30px;">
<i class="iconlogo" style="font-size: 80px;">㐵</i>
<span>Mock.js</span>
</h1>
<p><a href="http://travis-ci.org/nuysoft/Mock"><img src="https://api.travis-ci.org/nuysoft/Mock.png?branch=master" alt="Build Status"></a>
<!-- [](http://badge.fury.io/gh/nuysoft%2FMock) -->
<!-- [](http://badge.fury.io/js/mockjs) -->
<!-- [](http://badge.fury.io/bo/mockjs) -->
<a href="https://github.com/nuysoft/Mock/"><img src="https://sourcegraph.com/api/repos/github.com/nuysoft/Mock/counters/views-24h.png" alt="Views in the last 24 hours"></a></p>
<p>Mock.js 是一款<!-- 有用且好用的 -->模拟数据生成器,旨在帮助前端攻城师独立于后端进行开发,帮助编写单元测试。提供了以下模拟功能:</p>
<ul>
<li>根据数据模板生成模拟数据</li>
<li>模拟 Ajax 请求,生成并返回模拟数据</li>
<li>基于 HTML 模板生成模拟数据</li>
</ul>
<h2 id="-">在线编辑器</h2>
<!-- 没有 Live Demo 的库都是耍流氓 -->
<ul>
<li><a href="./editor.html#help">数据模板编辑器</a></li>
<li><a href="./demo/mock4tpl.html">Handlebars & Mustache</a></li>
<li><a href="./demo/mock4xtpl.html">KISSY XTemplate</a></li>
</ul>
<h2 id="-">下载</h2>
<p>
<a href="./dist/mock.js" class="btn btn-success w250">
Development Version (0.1.10)
</a> - <i>73kB, Uncompressed</i>
</p>
<p>
<a href="./dist/mock-min.js" class="btn btn-primary w250">
Production Version (0.1.10)
</a> - <i>32kB, Minified</i>
</p>
<p>
<a href="https://github.com/nuysoft/Mock" class="btn btn-default w250">
从 Github 获取最新版本
</a> - <i>Unreleased</i>
</p>
<iframe src="http://ghbtns.com/github-btn.html?user=nuysoft&repo=Mock&type=watch&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="131" height="30"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=nuysoft&repo=Mock&type=fork&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="140" height="30"></iframe>
<!-- <iframe src="http://ghbtns.com/github-btn.html?user=nuysoft&type=follow&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="165" height="30"></iframe> -->
<h2 id="-">分享文档</h2>
<ul>
<li><a href="/doc/lanlan.html">懒懒交流会 2014.5.30</a></li>
</ul>
<h2 id="-">用法</h2>
<h3 id="-">浏览器</h3>
<iframe width="100%" height="200" src="http://jsfiddle.net/DgJrj/embedded/html,js,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<h3 id="node-commonjs-">Node (CommonJS)</h3>
<pre><code>// 安装
npm install mockjs
// 使用
var Mock = require('mockjs');
var data = Mock.mock({
'list|1-10': [{
'id|+1': 1
}]
});
console.log(JSON.stringify(data, null, 4))</code></pre>
<h3 id="bower">Bower</h3>
<!-- If you'd like to use [bower](http://bower.io/), it's as easy as: -->
<pre><code>npm install -g bower
bower install --save mockjs
<script type="text/javascript" src="./bower_components/mockjs/dist/mock.js"></script></code></pre>
<h3 id="requirejs-amd-">RequireJS (AMD)</h3>
<iframe width="100%" height="350" src="http://jsfiddle.net/uTSqT/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<h3 id="sea-js-cmd-">Sea.js (CMD)</h3>
<iframe width="100%" height="350" src="http://jsfiddle.net/5jX6e/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<h3 id="kissy">KISSY</h3>
<iframe width="100%" height="400" src="http://jsfiddle.net/En2sX/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<!--
Mock.js 已入驻 [KISSY Gallery](https://github.com/kissygalleryteam),阿里同学可以直接加载 `gallery/Mock/0.1.1/index`:
<iframe width="100%" height="400" src="http://jsfiddle.net/8VNQQ/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
-->
<h3 id="random-cli">Random CLI</h3>
<pre><code>// 安装
npm install mockjs -g
// 执行
$ random url
// => http://rmcpx.org/funzwc</code></pre>
<hr>
<h2 id="-">语法规范</h2>
<p>Mock.js 的语法规范包括两部分:</p>
<ol>
<li>数据模板定义(Data Temaplte Definition,DTD)</li>
<li>数据占位符定义(Data Placeholder Definition,DPD)</li>
</ol>
<h3 id="-dtd">数据模板定义 DTD</h3>
<p><strong>数据模板中的每个属性由 3 部分构成:属性名、生成规则、属性值:</strong></p>
<pre><code>// 属性名 name
// 生成规则 rule
// 属性值 value
'name|rule': value</code></pre>
<p><strong>注意:</strong></p>
<ul>
<li>属性名 和 生成规则 之间用 <code>|</code> 分隔。</li>
<li>生成规则 是可选的。</li>
<li>生成规则 有 7 种格式:<ol>
<li><code>'name|min-max': value</code></li>
<li><code>'name|count': value</code></li>
<li><code>'name|min-max.dmin-dmax': value</code></li>
<li><code>'name|min-max.dcount': value</code></li>
<li><code>'name|count.dmin-dmax': value</code></li>
<li><code>'name|count.dcount': value</code></li>
<li><code>'name|+step': value</code></li>
</ol>
</li>
<li><strong>生成规则 的 含义 需要依赖 属性值 才能确定。</strong></li>
<li>属性值 中可以含有 <code>@占位符</code>。</li>
<li>属性值 还指定了最终值的初始值和类型。</li>
</ul>
<!-- 感谢 @麦少 同学对 Mock.js 语法的整理和分析,才有了这版相对清晰的语法文档。 -->
<p><strong>生成规则和示例:</strong></p>
<ol>
<li>属性值是字符串 <strong>String</strong><ol>
<li><code>'name|min-max': 'value'</code> 通过重复 <code>'value'</code> 生成一个字符串,重复次数大于等于 <code>min</code>,小于等于 <code>max</code>。</li>
<li><code>'name|count': 'value'</code> 通过重复 <code>'value'</code> 生成一个字符串,重复次数等于 <code>count</code>。</li>
</ol>
</li>
<li><p>属性值是数字 <strong>Number</strong></p>
<ol>
<li><code>'name|+1': 100</code> 属性值自动加 1,初始值为 100</li>
<li><code>'name|1-100': 100</code> 生成一个大于等于 1、小于等于 100 的整数,属性值 100 只用来确定类型。</li>
<li><p><code>'name|1-100.1-10': 100</code> 生成一个浮点数,整数部分大于等于 1、小于等于 100,小数部分保留 1 到 10 位。</p>
<pre><code> {
'number1|1-100.1-10': 1,
'number2|123.1-10': 1,
'number3|123.3': 1,
'number4|123.10': 1.123
}
// =>
{
"number1": 12.92,
"number2": 123.51,
"number3": 123.777,
"number4": 123.1231091814
}</code></pre>
</li>
</ol>
</li>
<li>属性值是布尔型 <strong>Boolean</strong><ol>
<li><code>'name|1': value</code> 随机生成一个布尔值,值为 true 的概率是 1/2,值为 false 的概率是 1/2。</li>
<li><code>'name|min-max': value</code> 随机生成一个布尔值,值为 <code>value</code> 的概率是 <code>min / (min + max)</code>,值为 <code>!value</code> 的概率是 <code>max / (min + max)</code>。</li>
</ol>
</li>
<li>属性值是对象 <strong>Object</strong><ol>
<li><code>'name|min-max': {}</code> 从属性值 <code>{}</code> 中随机选取 <code>min</code> 到 <code>max</code> 个属性。</li>
<li><code>'name|count': {}</code> 从属性值 <code>{}</code> 中随机选取 <code>count</code> 个属性。</li>
</ol>
</li>
<li>属性值是数组 <strong>Array</strong><ol>
<li><code>'name|1': [{}, {} ...]</code> 从属性值 <code>[{}, {} ...]</code> 中随机选取 1 个元素,作为最终值。</li>
<li><code>'name|min-max': [{}, {} ...]</code> 通过重复属性值 <code>[{}, {} ...]</code> 生成一个新数组,重复次数大于等于 <code>min</code>,小于等于 <code>max</code>。</li>
<li><code>'name|count': [{}, {} ...]</code> 通过重复属性值 <code>[{}, {} ...]</code> 生成一个新数组,重复次数为 <code>count</code>。</li>
</ol>
</li>
<li><p>属性值是数组 <strong>Function</strong></p>
<p> <code>'name': function(){}</code> 执行函数 <code>function(){}</code>,取其返回值作为最终的属性值,上下文为 <code>'name'</code> 所在的对象。</p>
</li>
</ol>
<h3 id="-dpd">数据占位符定义 DPD</h3>
<p>占位符 只是在属性值字符串中占个位置,并不出现在最终的属性值中。占位符 的格式为:</p>
<pre><code>@占位符
@占位符(参数 [, 参数])</code></pre>
<p><strong>注意:</strong></p>
<ol>
<li>用 <code>@</code> 来标识其后的字符串是 占位符。</li>
<li>占位符 引用的是 <code>Mock.Random</code> 中的方法。</li>
<li>通过 <code>Mock.Random.extend()</code> 来扩展自定义占位符。</li>
<li>占位符 也可以引用 数据模板 中的属性。</li>
<li><p>占位符 会优先引用 数据模板 中的属性。</p>
<pre><code> {
name: {
first: '@FIRST',
middle: '@FIRST',
last: '@LAST',
full: '@first @middle @last'
}
}
// =>
{
"name": {
"first": "Charles",
"middle": "Brenda",
"last": "Lopez",
"full": "Charles Brenda Lopez"
}
}</code></pre>
</li>
</ol>
<hr>
<h2 id="mock">Mock</h2>
<h3 id="mock-mock-rurl-rtype-template-function-options-">Mock.mock( rurl?, rtype?, template|function(options) )</h3>
<p>根据数据模板生成模拟数据。</p>
<ul>
<li><p><strong>Mock.mock( template )</strong></p>
<p> 根据数据模板生成模拟数据。</p>
</li>
<li><p><strong>Mock.mock( rurl, template )</strong></p>
<p> 记录数据模板。当拦截到匹配 <code>rurl</code> 的 Ajax 请求时,将根据数据模板 <code>template</code> 生成模拟数据,并作为响应数据返回。</p>
</li>
<li><p><strong>Mock.mock( rurl, function(options) )</strong></p>
<p> 记录用于生成响应数据的函数。当拦截到匹配 <code>rurl</code> 的 Ajax 请求时,函数 <code>function(options)</code> 将被执行,并把执行结果作为响应数据返回。</p>
</li>
<li><p><strong>Mock.mock( rurl, rtype, template )</strong></p>
<p> 记录数据模板。当拦截到匹配 <code>rurl</code> 和 <code>rtype</code> 的 Ajax 请求时,将根据数据模板 <code>template</code> 生成模拟数据,并作为响应数据返回。</p>
</li>
<li><p><strong>Mock.mock( rurl, rtype, function(options) )</strong></p>
<p> 记录用于生成响应数据的函数。当拦截到匹配 <code>rurl</code> 和 <code>rtype</code> 的 Ajax 请求时,函数 <code>function(options)</code> 将被执行,并把执行结果作为响应数据返回。</p>
</li>
</ul>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li><strong>参数 rurl</strong>:可选。表示需要拦截的 URL,可以是 URL 字符串或 URL 正则。例如 <code>/\/domain\/list\.json/</code>、<code>'/domian/list.json'</code>。</li>
<li><strong>参数 rtype</strong>:可选。表示需要拦截的 Ajax 请求类型。例如 <code>GET</code>、<code>POST</code>、<code>PUT</code>、<code>DELETE</code> 等。</li>
<li><strong>参数 template</strong>:可选。表示数据模板,可以是对象或字符串。例如 <code>{ 'data|1-10':[{}] }</code>、<code>'@EMAIL'</code>。</li>
<li><strong>参数 function(options)</strong>:可选。表示用于生成响应数据的函数。</li>
<li><strong>参数 options</strong>:指向本次请求的 Ajax 选项集。</li>
</ul>
<p>下面是 Mock.mock() 的 5 种参数格式以及语法规范的使用示例:</p>
<p><strong>示例1:</strong>Mock.mock( template )</p>
<iframe width="100%" height="300" src="http://jsfiddle.net/Y3rg6/1/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<p><strong>示例2:</strong>Mock.mock( rurl, template )</p>
<iframe width="100%" height="300" src="http://jsfiddle.net/BeENf/3/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<p><strong>示例3:</strong>Mock.mock( rurl, function(options) )</p>
<iframe width="100%" height="300" src="http://jsfiddle.net/2s5t5/3/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<p><strong>示例4:</strong>Mock.mock( rurl, rtype, template )</p>
<iframe width="100%" height="300" src="http://jsfiddle.net/Eq68p/2/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<p><strong>示例5:</strong>Mock.mock( rurl, rtype, function(options) )</p>
<iframe width="100%" height="300" src="http://jsfiddle.net/6dpV5/4/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<h3 id="mock-mockjax-library-">Mock.mockjax(library)</h3>
<p>覆盖(拦截) Ajax 请求,目前内置支持 jQuery、Zepto、KISSY。</p>
<p>对 jQuery Ajax 请求的拦截和响应,通过覆盖前置过滤器、选项 dataFilter 以及数据转换器实现,实现代码请问<a href="https://github.com/nuysoft/Mock/blob/master/src/mockjax.js#L5">这里</a>。</p>
<p>对 KISSY Ajax 请求的拦截和响应,则通过粗鲁地覆盖 KISSY.io(options) 实现,实现代码请问<a href="https://github.com/nuysoft/Mock/blob/master/src/mockjax.js#L72">这里</a>。</p>
<p>因为第三库 Ajax 的实现方式不尽相同,故目前只内置支持了实际开发中(本人和所服务的阿里) 常用的 jQuery、Zepto 和 KISSY。如果需要拦截其他第三方库的 Ajax 请求,可参考对 jQuery、Zepto 和 KISSY 的实现,覆盖 <code>Mock.mockjax(library)</code>。</p>
<p>通过方法 <code>Mock.mock( rurl, rtype, template|function(options) )</code> 设置的 URL 和数据模板的映射,均记录在属性 <code>Mock._mocked</code> 中,扩展时可从中获取 URL 对应的数据模板,进而生成和响应模拟数据。<code>Mock._mocked</code> 的数据结构为:</p>
<pre><code>{
(rurl + rtype): {
rurl: rurl,
rtype: rtype,
template: template
},
...
}</code></pre>
<!-- 如果业务和场景需要,可以联系 [@墨智]()、[nuysoft]([email protected]) 提供对特定库的内置支持,不过最酷的做法是开发人员能够为 Mock.js 贡献代码。 -->
<!-- 感谢 @麦少 同学对 Mock.mockjax(library) 的重构,并增加了对 Zepto.js 的支持。 -->
<h3 id="mock-tpl-input-options-helpers-partials-">Mock.tpl(input, options, helpers, partials)</h3>
<ul>
<li>Mock.tpl(input)</li>
<li>Mock.tpl(input, options)</li>
<li>Mock.tpl(input, options, helpers)</li>
<li>Mock.tpl(input, options, helpers, partials)</li>
</ul>
<p>基于 Handlebars、Mustache 的 HTML 模板生成模拟数据。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li><strong>参数 input</strong>:必选。可以是 HTML 模板,或者经过 Handlebars 解析的语法树(<code>Handlebars.parse(input)</code>)。将基于该参数生成模拟数据。</li>
<li><strong>参数 options</strong>:可选。对象。称为“数据模板”,用于配置生成模拟数据的规则。例如 <code>{ 'email': '@EMAIL' }</code>,在生成模拟数据时,所有 <code>email</code> 属性对应的值将是一个邮件地址。</li>
<li><strong>参数 helpers</strong>:可选。对象。表示局部 helper。全局 helper 会自动从 <code>Handlebars.helpers</code> 中读取。</li>
<li><strong>参数 partials</strong>:可选。对象。表示局部子模板。全局子模板会自动从 <code>Handlebars.partials</code> 中读取。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>// 基于 HTML 模板生成模拟数据
Mock.tpl('this is {{title}}!')
// => {title: "title"}
// 基于 HTML 模板和数据模板生成模拟数据
Mock.tpl('this is {{title}}!', {
title: '@TITLE'
})
// => {title: "Guhwbgehq Isuzssx Ywvwt Dkp"}
// 基于 HTML 模板生成模拟数据,传入了局部命令。
Mock.tpl('this is {{title}}!', {}, {
title: function(){
return 'my title'
}
})
// => {title: "title"}
// 基于 HTML 模板生成模拟数据,传入了局部子模板。
Mock.tpl('{{> "sub-tpl"}}', {}, {}, {
'sub-tpl': '{{title}}'
})
// => {title: "title"}</code></pre>
<p>数据模板 <code>options</code> 可以在调用 Mock.tpl(input, options, helpers, partials) 时传入,也可以在 HTML 模板中通过 HTML 注释配置(为了避免侵入现有的代码和开发模式),格式为 <code><!-- Mock {} --></code> 。下面的 2 个示例演示了通过 HTML 注释配置数据模板的两种方式:集中配置、分散配置。</p>
<p><strong>示例1:</strong>在 HTML 模板中通过一个 HTML 注释<strong>集中</strong>配置数据模板。</p>
<pre><code>var tpl = Mock.heredoc(function() {
/*!
{{email}}{{age}}
<!-- Mock {
email: '@EMAIL',
age: '@INT(1,100)'
} -->
*/
})
var data = Mock.tpl(tpl)
console.log(JSON.stringify(data, null, 4))
// =>
{
"email": "[email protected]",
"age": 33
}</code></pre>
<p><strong>示例2:</strong>在 HTML 模板中通过多个 HTML 注释<strong>分散</strong>配置数据模板。</p>
<pre><code>var tpl = Mock.heredoc(function() {
/*!
{{email}}{{age}}
<!-- Mock {
email: '@EMAIL'
} -->
<!-- Mock { age: '@INT(1,100)' } -->
*/
})
var data = Mock.tpl(tpl)
console.log(JSON.stringify(data, null, 4))
// =>
{
"email": "[email protected]",
"age": 83
}</code></pre>
<h3 id="mock-xtpl-input-options-helpers-partials-">Mock.xtpl(input, options, helpers, partials)</h3>
<ul>
<li>Mock.xtpl(input)</li>
<li>Mock.xtpl(input, options)</li>
<li>Mock.xtpl(input, options, helpers)</li>
<li>Mock.xtpl(input, options, helpers, partials)</li>
</ul>
<p>基于 KISSY XTempalte 的 HTML 模板生成模拟数据。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li><strong>参数 input</strong>:必选。可以是 HTML 模板,或者经过 KISSY XTempalte 解析的语法树(<code>XTemplate.compiler.parse(input)</code>)。将基于该参数生成模拟数据。</li>
<li><strong>参数 options</strong>:可选。对象。称为“数据模板”,用于配置生成模拟数据的规则。例如 <code>{ 'email': '@EMAIL' }</code>,在生成模拟数据时,所有 <code>email</code> 属性对应的值将是一个邮件地址。</li>
<li><strong>参数 helpers</strong>:可选。对象。表示局部命令。全局命令会自动从 <code>XTemplate.RunTime.commands</code> 中读取。</li>
<li><strong>参数 partials</strong>:可选。对象。表示局部子模板。全局子模板会自动从 <code>XTemplate.RunTime.subTpls</code> 中读取。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>// 基于 HTML 模板生成模拟数据
Mock.xtpl('this is {{title}}!')
// => {title: "title"}
// 基于 HTML 模板和数据模板生成模拟数据
Mock.xtpl('this is {{title}}!', {
title: '@TITLE'
})
// => {title: "Guhwbgehq Isuzssx Ywvwt Dkp"}
// 基于 HTML 模板生成模拟数据,传入了局部命令。
Mock.xtpl('this is {{title}}!', {}, {
title: function(){
return 'my title'
}
})
// => {title: "title"}
// 基于 HTML 模板生成模拟数据,传入了局部子模板。
Mock.xtpl('{{include "sub-tpl"}}', {}, {}, {
'sub-tpl': '{{title}}'
})
// => {title: "title"}</code></pre>
<p>数据模板 <code>options</code> 可以在调用 Mock.xtpl(input, options, helpers, partials) 时传入,也可以在 HTML 模板中通过 HTML 注释配置(为了避免侵入现有的代码和开发模式),格式为 <code><!-- Mock {} --></code> 。下面的 2 个示例演示了通过 HTML 注释配置数据模板的两种方式:集中配置、分散配置。</p>
<p><strong>示例1:</strong>在 HTML 模板中通过一个 HTML 注释<strong>集中</strong>配置数据模板。</p>
<pre><code>var tpl = Mock.heredoc(function() {
/*!
{{email}}{{age}}
<!-- Mock {
email: '@EMAIL',
age: '@INT(1,100)'
} -->
*/
})
var data = Mock.xtpl(tpl)
console.log(JSON.stringify(data, null, 4))
// =>
{
"email": "[email protected]",
"age": 33
}</code></pre>
<p><strong>示例2:</strong>在 HTML 模板中通过多个 HTML 注释<strong>分散</strong>配置数据模板。</p>
<pre><code>var tpl = Mock.heredoc(function() {
/*!
{{email}}{{age}}
<!-- Mock {
email: '@EMAIL'
} -->
<!-- Mock { age: '@INT(1,100)' } -->
*/
})
var data = Mock.xtpl(tpl)
console.log(JSON.stringify(data, null, 4))
// =>
{
"email": "[email protected]",
"age": 83
}</code></pre>
<h3 id="mock-heredoc-fn-">Mock.heredoc(fn)</h3>
<ul>
<li>Mock.heredoc(fn)</li>
</ul>
<p>以直观、舒适、安全的方式书写(多行)HTML 模板。</p>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>var tpl = Mock.heredoc(function() {
/*!
{{email}}{{age}}
<!-- Mock {
email: '@EMAIL',
age: '@INT(1,100)'
} -->
*/
})
console.log(tpl)
// =>
"{{email}}{{age}}
<!-- Mock {
email: '@EMAIL',
age: '@INT(1,100)'
} -->"</code></pre>
<p><strong>相关阅读</strong></p>
<ul>
<li><a href="http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript">Creating multiline strings in JavaScript</a>、</li>
</ul>
<h2 id="mock-random">Mock.Random</h2>
<p>Mock.Random 是一个工具类,用于生成各种随机数据。Mock.Random 的方法在数据模板中称为“占位符”,引用格式为 <code>@占位符(参数 [, 参数])</code> 。例如:</p>
<pre><code>var Random = Mock.Random;
Random.email()
// => "[email protected]"
Mock.mock('@EMAIL')
// => "[email protected]"
Mock.mock( { email: '@EMAIL' } )
// => { email: "[email protected]" }</code></pre>
<p>可以在上面的例子中看到,直接调用 'Random.email()' 时方法名 <code>email()</code> 是小写的,而数据模板中的 <code>@EMAIL</code> 却是大写。这并非对数据模板中的占位符做了特殊处理,也非强制的编写方式,事实上在数据模板中使用小写的 <code>@email</code> 也可以达到同样的效果。不过,这是建议的编码风格,以便在阅读时从视觉上提高占位符的识别度,快速识别占位符和普通字符。</p>
<p>在浏览器中,为了减少需要拼写的字符,Mock.js 把 Mock.Random 暴露给了 window 对象,使之成为全局变量,从而可以直接访问 Random。因此上面例子中的 <code>var Random = Mock.Random;</code> 可以省略。在后面的例子中,也将做同样的处理。</p>
<blockquote>
<p>在 Node.js 中,仍然需要通过 <code>Mock.Random</code> 访问。</p>
</blockquote>
<p>Mock.Random 提供的完整方法(占位符)如下:</p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Method</th>
</tr>
</thead>
<tbody>
<tr>
<td>Basics</td>
<td>boolean natural integer float character string range date time datetime now</td>
</tr>
<tr>
<td>Image</td>
<td>image dataImage</td>
</tr>
<tr>
<td>Color</td>
<td>color</td>
</tr>
<tr>
<td>Text</td>
<td>paragraph sentence word title</td>
</tr>
<tr>
<td>Name</td>
<td>first last name</td>
</tr>
<tr>
<td>Web</td>
<td>url domain email ip tld</td>
</tr>
<tr>
<td>Address</td>
<td>area region</td>
</tr>
<tr>
<td>Helpers</td>
<td>capitalize upper lower pick shuffle</td>
</tr>
<tr>
<td>Miscellaneous</td>
<td>guid id</td>
</tr>
</tbody>
</table>
<script id="fixPlaceholderLink" type="text/javascript">
$('#fixPlaceholderLink').prev('table')
.find('td:nth-child(1)').each(function(index, td) {
$(td).contents().wrapAll(
$('<a>').attr('href', '#' + $(td).text())
)
})
.end()
.find('td:nth-child(2)').each(function(index, td) {
var methods = $(td).text().split(' ')
var links = $()
$(methods).each(function(mindex, m) {
links.push(
$('<a>').attr('href', '#' + m).text(m)[0]
)
if (mindex < methods.length - 1) {
links.push(
$('<span>').text(', ')[0]
)
}
})
$(td).empty().append(links)
})
.end()
</script>
<p>Mock.Random 中的方法与数据模板的 <code>@占位符</code> 一一对应,在需要时可以为 Mock.Random 扩展方法,然后在数据模板中通过 <code>@扩展方法</code> 引用。例如:</p>
<pre><code>Random.extend({
constellations: ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座'],
constellation: function(date){
return this.pick(this.constellations)
}
})
Random.constellation()
// => "水瓶座"
Mock.mock('@CONSTELLATION')
// => "天蝎座"
Mock.mock({ constellation: '@CONSTELLATION'})
// => { constellation: "射手座" }</code></pre>
<p>下面是 Mock.Random 内置支持的方法说明。</p>
<p><strong>你可以打开控制台,随意地试验这些方法。</strong></p>
<h3 id="basics">Basics</h3>
<h4 id="random-boolean-min-max-cur-">Random.boolean(min, max, cur)</h4>
<ul>
<li>Random.boolean()</li>
<li>Random.boolean(min, max, cur)</li>
</ul>
<p>返回一个随机的布尔值。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 min:可选。指示参数 cur 出现的概率。概率计算公式为 <code>min / (min + max)</code>。该参数的默认值为 1,即有 50% 的概率返回参数 cur。</li>
<li>参数 max:可选。指示参数 cur 的相反值(!cur)出现的概率。概率计算公式为 <code>max / (min + max)</code>。该参数的默认值为 1,即有 50% 的概率返回参数 cur。</li>
<li>参数 cur:可选。可选值为布尔值 true 或 false。如果未传入任何参数,则返回 true 和 false 的概率各为 50%。该参数没有默认值,在该方法的内部,依据原生方法 Math.random() 返回的(浮点)数来计算和返回布尔值,例如在最简单的情况下,返回值是表达式 <code>Math.random() >= 0.5</code> 的执行结果。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.boolean()
// => true
Random.boolean(1, 9, true)
// => false
Random.bool()
// => false
Random.bool(1, 9, false)
// => true</code></pre>
<!-- 事实上,原生方法 Math.random() 返回的随机(浮点)数的分布并不均匀,是货真价实的伪随机数,将来会替换为基于 ?? 来生成随机数。?? 对 Math.random() 的实现机制进行了分析和统计,并提供了随机数的参考实现,可以访问[这里](http://??)。
TODO 统计 -->
<h4 id="random-natural-min-max-">Random.natural(min, max)</h4>
<ul>
<li>Random.natural()</li>
<li>Random.natural(min)</li>
<li>Random.natural(min, max)</li>
</ul>
<p>返回一个随机的自然数(大于等于 0 的整数)。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 min:可选。指示随机自然数的最小值。默认值为 0。</li>
<li>参数 max:可选。指示随机自然数的最小值。默认值为 9007199254740992。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.natural()
// => 1002794054057984
Random.natural(10000)
// => 71529071126209
Random.natural(60, 100)
// => 77</code></pre>
<h4 id="random-integer-min-max-">Random.integer(min, max)</h4>
<ul>
<li>Random.integer()</li>
<li>Random.integer(min)</li>
<li>Random.integer(min, max)</li>
</ul>
<p>返回一个随机的整数。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 min:可选。指示随机整数的最小值。默认值为 -9007199254740992。</li>
<li>参数 max:可选。指示随机整数的最大值。默认值为 9007199254740992。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.integer()
// => -3815311811805184
Random.integer(10000)
// => 4303764511003750
Random.integer(60,100)
// => 96</code></pre>
<h4 id="random-float-min-max-dmin-dmax-">Random.float(min, max, dmin, dmax)</h4>
<ul>
<li>Random.float()</li>
<li>Random.float(min)</li>
<li>Random.float(min, max)</li>
<li>Random.float(min, max, dmin)</li>
<li>Random.float(min, max, dmin, dmax)</li>
</ul>
<p>返回一个随机的浮点数。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 min:可选。整数部分的最小值。默认值为 -9007199254740992。</li>
<li>参数 max:可选。整数部分的最大值。默认值为 9007199254740992。</li>
<li>参数 dmin:可选。小数部分位数的最小值。默认值为 0。</li>
<li>参数 dmin:可选。小数部分位数的最大值。默认值为 17。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.float()
// => -1766114241544192.8
Random.float(0)
// => 556530504040448.25
Random.float(60, 100)
// => 82.56779679549358
Random.float(60, 100, 3)
// => 61.718533677927894
Random.float(60, 100, 3, 5)
// => 70.6849</code></pre>
<h4 id="random-character-pool-">Random.character(pool)</h4>
<p>返回一个随机字符。</p>
<ul>
<li>Random.character()</li>
<li>Random.character('lower/upper/number/symbol')</li>
<li>Random.character(pool)</li>
</ul>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li><p>参数 pool:可选。字符串。表示字符池,将从中选择一个字符返回。</p>
<ul>
<li><p>如果传入 <code>'lower'</code> 或 <code>'upper'</code>、<code>'number'</code>、<code>'symbol'</code>,表示从内置的字符池从选取:</p>
<pre><code> {
lower: "abcdefghijklmnopqrstuvwxyz",
upper: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
number: "0123456789",
symbol: "!@#$%^&*()[]"
}</code></pre>
</li>
<li><p>如果未传入该参数,则从 <code>'lower' + 'upper' + 'number' + 'symbol'</code> 中随机选取一个字符返回。</p>
</li>
</ul>
</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.character()
// => "P"
Random.character('lower')
// => "y"
Random.character('upper')
// => "X"
Random.character('number')
// => "1"
Random.character('symbol')
// => "&"
Random.character('aeiou')
// => "u"</code></pre>
<h4 id="random-string-pool-min-max-">Random.string(pool, min, max)</h4>
<p>返回一个随机字符串。</p>
<ul>
<li>Random.string()</li>
<li>Random.string( length )</li>
<li>Random.string( pool, length )</li>
<li>Random.string( min, max )</li>
<li>Random.string( pool, min, max )</li>
</ul>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li><p>参数 pool:可选。字符串。表示字符池,将从中选择一个字符返回。</p>
<ul>
<li><p>如果传入 <code>'lower'</code> 或 <code>'upper'</code>、<code>'number'</code>、<code>'symbol'</code>,表示从内置的字符池从选取:</p>
<pre><code> {
lower: "abcdefghijklmnopqrstuvwxyz",
upper: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
number: "0123456789",
symbol: "!@#$%^&*()[]"
}</code></pre>
</li>
<li><p>如果未传入该参数,则从 <code>'lower' + 'upper' + 'number' + 'symbol'</code> 中随机选取一个字符返回。</p>
</li>
</ul>
</li>
<li>参数 min:可选。随机字符串的最小长度。默认值为 3。</li>
<li>参数 max:可选。随机字符串的最大长度。默认值为 7。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.string()
// => "pJjDUe"
Random.string( 5 )
// => "GaadY"
Random.string( 'lower', 5 )
// => "jseqj"
Random.string( 7, 10 )
// => "UuGQgSYk"
Random.string( 'aeiou', 1, 3 )
// => "ea"</code></pre>
<h4 id="random-range-start-stop-step-">Random.range(start, stop, step)</h4>
<ul>
<li>Random.range(stop)</li>
<li>Random.range(start, stop)</li>
<li>Random.range(start, stop, step)</li>
</ul>
<p>返回一个整型数组。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 start:必选。数组中整数的起始值。</li>
<li>参数 stop:可选。数组中整数的结束值(不包含在返回值中)。</li>
<li>参数 step:可选。数组中整数之间的步长。默认值为 1。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.range(10)
// => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Random.range(3, 7)
// => [3, 4, 5, 6]
Random.range(1, 10, 2)
// => [1, 3, 5, 7, 9]
Random.range(1, 10, 3)
// => [1, 4, 7]</code></pre>
<h4 id="random-date-format-">Random.date(format)</h4>
<ul>
<li>Random.date()</li>
<li>Random.date(format)</li>
</ul>
<p>返回一个随机的日期字符串。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 format:可选。指示生成的日期字符串的格式。默认值为 <code>yyyy-MM-dd</code>。可选的占位符参考自 <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Date">Ext.Date</a>,如下所示:</li>
</ul>
<table>
<thead>
<tr>
<th>Format</th>
<th>Description</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>yyyy</td>
<td>A full numeric representation of a year, 4 digits</td>
<td>1999 or 2003</td>
</tr>
<tr>
<td>yy</td>
<td>A two digit representation of a year</td>
<td>99 or 03</td>
</tr>
<tr>
<td>y</td>
<td>A two digit representation of a year</td>
<td>99 or 03</td>
</tr>
<tr>
<td>MM</td>
<td>Numeric representation of a month, with leading zeros</td>
<td>01 to 12</td>
</tr>
<tr>
<td>M</td>
<td>Numeric representation of a month, without leading zeros</td>
<td>1 to 12</td>
</tr>
<tr>
<td>dd</td>
<td>Day of the month, 2 digits with leading zeros</td>
<td>01 to 31</td>
</tr>
<tr>
<td>d</td>
<td>Day of the month without leading zeros</td>
<td>1 to 31</td>
</tr>
<tr>
<td>HH</td>
<td>24-hour format of an hour with leading zeros</td>
<td>00 to 23</td>
</tr>
<tr>
<td>H</td>
<td>24-hour format of an hour without leading zeros</td>
<td>0 to 23</td>
</tr>
<tr>
<td>hh</td>
<td>12-hour format of an hour without leading zeros</td>
<td>1 to 12</td>
</tr>
<tr>
<td>h</td>
<td>12-hour format of an hour with leading zeros</td>
<td>01 to 12</td>
</tr>
<tr>
<td>mm</td>
<td>Minutes, with leading zeros</td>
<td>00 to 59</td>
</tr>
<tr>
<td>m</td>
<td>Minutes, without leading zeros</td>
<td>0 to 59</td>
</tr>
<tr>
<td>ss</td>
<td>Seconds, with leading zeros</td>
<td>00 to 59</td>
</tr>
<tr>
<td>s</td>
<td>Seconds, without leading zeros</td>
<td>0 to 59</td>
</tr>
<tr>
<td>SS</td>
<td>Milliseconds, with leading zeros</td>
<td>000 to 999</td>
</tr>
<tr>
<td>S</td>
<td>Milliseconds, without leading zeros</td>
<td>0 to 999</td>
</tr>
<tr>
<td>A</td>
<td>Uppercase Ante meridiem and Post meridiem</td>
<td>AM or PM</td>
</tr>
<tr>
<td>a</td>
<td>Lowercase Ante meridiem and Post meridiem</td>
<td>am or pm</td>
</tr>
<tr>
<td>T</td>
<td>Milliseconds, since 1970-1-1 00:00:00 UTC</td>
<td>759883437303</td>
</tr>
</tbody>
</table>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.date()
// => "2002-10-23"
Random.date('yyyy-MM-dd')
// => "1983-01-29"
Random.date('yy-MM-dd')
// => "79-02-14"
Random.date('y-MM-dd')
// => "81-05-17"
Random.date('y-M-d')
// => "84-6-5"</code></pre>
<h4 id="random-time-format-">Random.time(format)</h4>
<ul>
<li>Random.time()</li>
<li>Random.time(format)</li>
</ul>
<p>返回一个随机的时间字符串。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 format:可选。指示生成的时间字符串的格式。默认值为 <code>HH:mm:ss</code>。可选的占位符参考自 <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Date">Ext.Date</a>,请参见 <a href="#date">Random.date(format)</a>。</li>
</ul>
<p><strong>使用示例</strong>如下所示:</p>
<pre><code>Random.time()
// => "00:14:47"
Random.time('A HH:mm:ss')
// => "PM 20:47:37"
Random.time('a HH:mm:ss')
// => "pm 17:40:00"
Random.time('HH:mm:ss')
// => "03:57:53"
Random.time('H:m:s')
// => "3:5:13"</code></pre>
<h4 id="random-datetime-format-">Random.datetime(format)</h4>
<ul>
<li>Random.datetime()</li>
<li>Random.datetime(format)</li>
</ul>
<p>返回一个随机的日期和时间字符串。</p>
<p><strong>参数的含义和默认值</strong>如下所示:</p>
<ul>
<li>参数 format:可选。指示生成的日期和时间字符串的格式。默认值为 <code>yyyy-MM-dd HH:mm:ss</code>。可选的占位符参考自 <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Date">Ext.Date</a>,请参见 <a href="#date">Random.date(format)</a>。</li>