Skip to content

Commit 7f18477

Browse files
committed
fix: utis.getValueFromObject
1 parent c9fa960 commit 7f18477

File tree

1 file changed

+4
-30
lines changed

1 file changed

+4
-30
lines changed

src/index.js

+4-30
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,17 @@
22
import action from '@cocreate/actions';
33
import observer from '@cocreate/observer';
44
import uuid from '@cocreate/uuid';
5-
import { queryDocumentSelector } from '@cocreate/utils';
5+
import { queryDocumentSelector, getValueFromObject } from '@cocreate/utils';
66
import '@cocreate/element-prototype';
77
import './index.css';
88
// import api from '@cocreate/api';
99

1010
const CoCreateRender = {
11-
// Can be called from utils getValueFromObject
12-
__getValueFromObject: function(json, path) {
13-
try {
14-
if (typeof json == 'undefined' || !path)
15-
return false;
16-
if (path.indexOf('.') == -1 && path.includes('collection'))
17-
json = this.dataOriginal
18-
if (/\[([0-9]*)\]/g.test(path)) {
19-
path = path.replace(/\[/g, '.');
20-
if (path.endsWith(']'))
21-
path = path.slice(0, -1)
22-
path = path.replace(/\]./g, '.');
23-
path = path.replace(/\]/g, '.');
24-
}
25-
let jsonData = json, subpath = path.split('.');
26-
27-
for (let i = 0; i < subpath.length; i++) {
28-
jsonData = jsonData[subpath[i]];
29-
if (!jsonData) return false;
30-
}
31-
return jsonData;
32-
}catch(error){
33-
console.log("Error in getValueFromObject", error);
34-
return false;
35-
}
36-
},
3711

3812
__getValue: function(data, attrValue) {
3913
let result = /{{\s*([\w\W]+)\s*}}/g.exec(attrValue);
4014
if (result) {
41-
return this.__getValueFromObject(data, result[1].trim());
15+
return getValueFromObject(data, result[1].trim());
4216
}
4317
return false;
4418
},
@@ -141,7 +115,7 @@ const CoCreateRender = {
141115
template.renderedKeys = new Map()
142116

143117
if (isRenderObject && type) {
144-
let Data = self.__getValueFromObject(arrayData, type);
118+
let Data = self.getValueFromObject(arrayData, type);
145119
let array = self.isRenderObject(Data, renderKey)
146120
for (let item of array) {
147121
if (!template.renderedKeys.has(item[renderKey].key)){
@@ -155,7 +129,7 @@ const CoCreateRender = {
155129
} else {
156130

157131
if (!Array.isArray(arrayData))
158-
arrayData = this.__getValueFromObject(data, type);
132+
arrayData = getValueFromObject(data, type);
159133

160134
if (!arrayData) {
161135
let cloneEl = this.cloneEl(template);

0 commit comments

Comments
 (0)