Skip to content

Commit 0ef42c7

Browse files
committed
fix: document_id was not inserting on some of the nested elements
1 parent dc75a5a commit 0ef42c7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const CoCreateRender = {
4141
return this.__getValueFromObject(data, result[1].trim());
4242
}
4343
return false;
44-
4544
},
4645

4746
__createObject: function (data, path) {
@@ -219,11 +218,17 @@ const CoCreateRender = {
219218
return cloneEl;
220219
},
221220

221+
document_id: '',
222222
setValue: function(els, data, renderArray, renderKey){
223223
if (!data) return;
224224
let isRenderKey
225225
if (data.renderKey)
226226
isRenderKey = true
227+
228+
if(data.document_id || data.data && data.data._id ) {
229+
let id = data.document_id || data.data._id;
230+
this.document_id = id;
231+
}
227232

228233
const that = this;
229234
Array.from(els).forEach(el => {
@@ -280,6 +285,12 @@ const CoCreateRender = {
280285
// ToDo support attibute name replace if has {{}}
281286
// attr_name = that.__replaceValue(data, attr_name, renderKey);
282287

288+
if (attr.value == "{{data._id}}" || attr.value == "{{document_id}}") {
289+
// if(data.data || data.document_id) {
290+
// let id = data.data._id || data.document_id;
291+
el.setAttribute(attr_name, this.document_id);
292+
// }
293+
}
283294
if (attrValue || attrValue == "") {
284295
el.setAttribute(attr_name, attrValue);
285296
}
@@ -473,6 +484,9 @@ observer.init({
473484
for (let data of array.reverse()){
474485
obj = {...obj, ...data}
475486
}
487+
488+
if (!obj['document_id'] && obj.data._id)
489+
obj['document_id'] = obj.data._id
476490

477491
CoCreateRender.data({
478492
elements: [element],

0 commit comments

Comments
 (0)