Skip to content

Commit 53cf9cb

Browse files
committed
update add to init
1 parent a464a3b commit 53cf9cb

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

demo/render.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ <h1>Paste in your browser console</h1>
4747

4848

4949
/** Example of array object from db -- render2 is an example of data-render_id**/
50-
CoCreate.render.data('[data-template_id=abc1]',{
50+
CoCreate.render.data({
51+
selector: '[data-template_id=abc1]',
52+
data: {
5153
render2: {
5254
collection : 'dededede',
5355
data: [{
@@ -85,6 +87,7 @@ <h1>Paste in your browser console</h1>
8587
},
8688
]
8789
}
90+
}
8891
})
8992

9093
</pre>

dist/CoCreate-render.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,37 @@ <h4 class="margin-top:20px padding:5px_0px">HTML Template</h4>
9595
<h4 class="margin-top:40px padding:5px_0px">CoCreate-render usage</h4>
9696
<p class="padding:10px_0px">Description.</p>
9797
<pre><code class="language-html">
98-
CoCreate.render.data('[data-template_id=abc1]',{
99-
render2: {
100-
collection : 'dededede',
101-
data: [{
102-
_id : '123kijfhgfkel45',
103-
firstname : 'Jin',
104-
lastname : 'codingmachinine',
105-
personal_info : {email:'jeanmendozar@gmail.com','phone':'56666'},
106-
email: 'tesing@gamil.com',
107-
testing_array : [
108-
{email:'jeanmendozar@gmail.com','phone':'0','home':'home1'},
109-
{email:'frank@gmail.com','phone':'1','home':'home2'},
110-
{email:'jose@gmail.com','phone':'2','home':'home3'},
111-
],
112-
string_array: ['string1', 'string2', 1, 3]
113-
},{
114-
_id : '5678efe32qd2ol',
115-
firstname : 'jean',
116-
lastname : 'Mendoza',
117-
personal_info : {email:'jeanmendozar@gmail.com','phone':'56666'},
118-
email: 'tesing2@gamil.com',
119-
testing_array : [
120-
{email:'1ana@gmail.com','phone':'16','home':'home17'},
121-
{email:'1rosa@gmail.com','phone':'17','home':'home18'},
122-
{email:'1nuevo@gmail.com','phone':'18','home':'home19'}
123-
],
124-
string_array: ['string1', 'string2', 1, 3]
125-
},
126-
]
127-
}
98+
CoCreate.render.data({
99+
selector: '[data-template_id=abc1]',
100+
data: {
101+
render2: {
102+
collection : 'dededede',
103+
data: [{
104+
_id : '123kijfhgfkel45',
105+
firstname : 'Jin',
106+
lastname : 'codingmachinine',
107+
personal_info : {email:'jeanmendozar@gmail.com','phone':'56666'},
108+
email: 'tesing@gamil.com',
109+
testing_array : [
110+
{email:'jeanmendozar@gmail.com','phone':'0','home':'home1'},
111+
{email:'frank@gmail.com','phone':'1','home':'home2'},
112+
{email:'jose@gmail.com','phone':'2','home':'home3'},
113+
],
114+
string_array: ['string1', 'string2', 1, 3]
115+
},{
116+
_id : '5678efe32qd2ol',
117+
firstname : 'jean',
118+
lastname : 'Mendoza',
119+
personal_info : {email:'jeanmendozar@gmail.com','phone':'56666'},
120+
email: 'tesing2@gamil.com',
121+
testing_array : [
122+
{email:'1ana@gmail.com','phone':'16','home':'home17'},
123+
{email:'1rosa@gmail.com','phone':'17','home':'home18'},
124+
{email:'1nuevo@gmail.com','phone':'18','home':'home19'}
125+
],
126+
string_array: ['string1', 'string2', 1, 3]
127+
},
128+
]}
128129
})
129130
</code></pre>
130131

src/CoCreate-render.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ const CoCreateRender = {
128128
});
129129
},
130130

131-
data : function(selector, dataResult) {
131+
data: function({selector, data, elements, passTo}) {
132+
if (selector) {
133+
this.render(selector, data);
134+
} else if (elements) {
135+
this.setValue(elements, data, passTo);
136+
}
137+
},
138+
139+
render : function(selector, dataResult) {
132140
let template_div = document.querySelector(selector)
133141
if (!template_div) {
134142
return;

0 commit comments

Comments
 (0)