1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {_dateToUTCString,_getField} from './row-util';
|
7 |
|
8 |
|
9 |
|
10 | const getValue = function (fieldName) {
|
11 | return _getField(this,fieldName)['value']
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | const getChildValue = function(fieldName){
|
19 | var nameArr = fieldName.split('.');
|
20 | var _name = nameArr[0];
|
21 | for (var i = 0, count = nameArr.length; i<count; i++){
|
22 | var _value = this.getValue(_name);
|
23 |
|
24 | if (i == count -1){
|
25 | if (_value instanceof u.DataTable){
|
26 | return _value.rows.peek();
|
27 | }else{
|
28 | return _value;
|
29 | }
|
30 | }else{
|
31 | if (_value instanceof u.DataTable){
|
32 | _value = _value.getCurrentRow();
|
33 | if (!_value)
|
34 | return '';
|
35 | else
|
36 | return _value.getChildValue(fieldName.replace(_name + '.', ''))
|
37 | }else{
|
38 | _name = _name + '.' + nameArr[i+1];
|
39 | }
|
40 |
|
41 | }
|
42 | }
|
43 | return '';
|
44 | };
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | const getData = function () {
|
51 | var data = ko.toJS(this.data)
|
52 | var meta = this.parent.getMeta()
|
53 | for (var key in meta) {
|
54 | if (meta[key] && meta[key].type) {
|
55 | if (meta[key].type == 'date' || meta[key].type == 'datetime') {
|
56 | if(key.indexOf('.')>0){
|
57 | var keys=key.split('.');
|
58 | var _keyValue=data;
|
59 | for(var i=0,count=keys.length;i<count;i++){
|
60 | _keyValue=_keyValue[keys[i]];
|
61 | }
|
62 | _keyValue.value =_dateToUTCString(_keyValue.value);
|
63 |
|
64 | }else{
|
65 | data[key].value = _dateToUTCString(data[key].value)
|
66 | }
|
67 | } else if(meta[key].type == 'child') {
|
68 | var chiddt = this.getValue(key),
|
69 | rs = chiddt.rows(),
|
70 | cds = [];
|
71 | for(var i=0;i < rs.length;i++) {
|
72 | cds.push(rs[i].getData());
|
73 | }
|
74 | data[key].value = JSON.stringify(cds);
|
75 | }
|
76 | }
|
77 | }
|
78 | return {'id': this.rowId, 'status': this.status, data: data}
|
79 | }
|
80 |
|
81 | const getEmptyData = function () {
|
82 | return {'id': this.rowId, 'status': this.status, data: {}}
|
83 | };
|
84 |
|
85 | export {
|
86 | getValue,
|
87 | getChildValue,
|
88 | getData,
|
89 | getEmptyData
|
90 | } |
\ | No newline at end of file |