UNPKG

2.93 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getEmptyData = exports.getData = exports.getChildValue = exports.getValue = undefined;
7
8var _rowUtil = require('./row-util');
9
10/**
11 *获取row中某一列的值
12 */
13var getValue = function getValue(fieldName) {
14 return (0, _rowUtil._getField)(this, fieldName)['value'];
15};
16
17/**
18 * 获取子表值 ,如果fieldName对应了一个子表,返回该子表的行数组
19 * @param fieldName
20 */
21/**
22 * Module : kero dataTable row getData
23 * Author : liuyk(liuyk@yonyou.com)
24 * Date : 2016-08-08 13:54:01
25 */
26var getChildValue = function getChildValue(fieldName) {
27 var nameArr = fieldName.split('.');
28 var _name = nameArr[0];
29 for (var i = 0, count = nameArr.length; i < count; i++) {
30 var _value = this.getValue(_name);
31 //最后一级
32 if (i == count - 1) {
33 if (_value instanceof u.DataTable) {
34 return _value.rows.peek();
35 } else {
36 return _value;
37 }
38 } else {
39 if (_value instanceof u.DataTable) {
40 _value = _value.getCurrentRow();
41 if (!_value) return '';else return _value.getChildValue(fieldName.replace(_name + '.', ''));
42 } else {
43 _name = _name + '.' + nameArr[i + 1];
44 }
45 }
46 }
47 return '';
48};
49
50/**
51 * @private
52 * 提交数据到后台
53 */
54var getData = function getData() {
55 var data = ko.toJS(this.data);
56 var meta = this.parent.getMeta();
57 for (var key in meta) {
58 if (meta[key] && meta[key].type) {
59 if (meta[key].type == 'date' || meta[key].type == 'datetime') {
60 if (key.indexOf('.') > 0) {
61 //大于0说明是多级json
62 var keys = key.split('.');
63 var _keyValue = data;
64 for (var i = 0, count = keys.length; i < count; i++) {
65 _keyValue = _keyValue[keys[i]];
66 }
67 _keyValue.value = (0, _rowUtil._dateToUTCString)(_keyValue.value);
68 } else {
69 data[key].value = (0, _rowUtil._dateToUTCString)(data[key].value);
70 }
71 } else if (meta[key].type == 'child') {
72 var chiddt = this.getValue(key),
73 rs = chiddt.rows(),
74 cds = [];
75 for (var i = 0; i < rs.length; i++) {
76 cds.push(rs[i].getData());
77 }
78 data[key].value = JSON.stringify(cds);
79 }
80 }
81 }
82 return { 'id': this.rowId, 'status': this.status, data: data };
83};
84
85var getEmptyData = function getEmptyData() {
86 return { 'id': this.rowId, 'status': this.status, data: {} };
87};
88
89exports.getValue = getValue;
90exports.getChildValue = getChildValue;
91exports.getData = getData;
92exports.getEmptyData = getEmptyData;
\No newline at end of file