UNPKG

1.84 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 */
24const getSimpleData = function(options) {
25 options = options || {}
26 var rows, _rowData = [],
27 type = options['type'] || 'all',
28 fields = options['fields'] || null;
29
30 if (type === 'all') {
31 rows = this.rows.peek();
32 } else if (type === 'current') {
33 var currRow = this.getCurrentRow();
34 rows = currRow == null ? [] : [currRow];
35 } else if (type === 'focus') {
36 var focusRow = this.getFocusRow();
37 rows = focusRow == null ? [] : [focusRow];
38 } else if (type === 'select') {
39 rows = this.getSelectedRows();
40 } else if (type === 'change') {
41 rows = this.getChangedRows();
42 }
43
44 for (var i = 0; i < rows.length; i++) {
45 _rowData.push(rows[i].getSimpleData({
46 fields: fields
47 }));
48 }
49 if (_rowData.length == 0) {
50 _rowData = this.setSimpleDataReal; //云采提的#需求
51 }
52 return _rowData;
53};
54
55
56
57export const getSimpleDataFunObj = {
58 getSimpleData: getSimpleData
59}