UNPKG

2.48 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable getSimpleData
3 * Author : liuyk(liuyk@yonyou.com)
4 * Date : 2016-08-01 14:34:01
5 */
6
7/**
8 * 获取数据信息,只获取字段名与字段值
9 * @memberof DataTable
10 * @param {object} [options] [description]
11 * @param {string} [options.type=all] 获取数据的规则
12 * all:所有数据
13 * current:当前行数据
14 * focus:焦点行数据
15 * select:选中行数据
16 * change:发生改变的数据
17 * @param {array} [options.fields] 需要获取数据的字段名数组
18 * @return {array} 获取到的数据信息
19 * @example
20 * datatable.getSimpleData() // 获取所有数据信息
21 * datatable.getSimpleData({type:'current'}) // 获取当前行数据信息
22 * datatable.getSimpleData({type:'current','fields':['filed1','field3']}) // 获取当前行field1和filed3数据信息
23 */
24var getSimpleData = function getSimpleData(options) {
25 options = options || {};
26 var rows,
27 _rowData = [],
28 type = options['type'] || 'all',
29 fields = options['fields'] || null;
30
31 if (type === 'current') {
32 var currRow = this.getCurrentRow();
33 rows = currRow == null ? [] : [currRow];
34 } else if (type === 'focus') {
35 var focusRow = this.getFocusRow();
36 rows = focusRow == null ? [] : [focusRow];
37 } else {
38 if (this.pageCache) {
39 var pages = this.getPages();
40 rows = [];
41 for (var i = 0; i < pages.length; i++) {
42 var page = pages[i];
43 if (type === 'all') {
44 rows = rows.concat(page.rows.peek());
45 } else if (type === 'select') {
46 rows = rows.concat(page.getSelectRows());
47 } else if (type === 'change') {
48 rows = rows.concat(page.getSelectRows());
49 }
50 }
51 } else {
52 if (type === 'all') {
53 rows = this.rows.peek();
54 } else if (type === 'select') {
55 rows = this.getSelectedRows();
56 } else if (type === 'change') {
57 rows = this.getChangedRows();
58 }
59 }
60 }
61
62 for (var i = 0; i < rows.length; i++) {
63 _rowData.push(rows[i].getSimpleData({
64 fields: fields
65 }));
66 }
67 if (_rowData.length == 0) {
68 _rowData = this.setSimpleDataReal; //云采提的#需求
69 }
70 return _rowData;
71};
72
73export var getSimpleDataFunObj = {
74 getSimpleData: getSimpleData
75};
\No newline at end of file