Arthur Brandao 5 жил өмнө
parent
commit
bde3542aee

+ 5 - 0
src/index.html

@@ -18,6 +18,7 @@
     <h3 data-bind="test"></h3>
     <h3 data-bind="test"></h3>
 
 
     <div data-loop="aze">
     <div data-loop="aze">
+      <h4>Loop</h4>
       <span data-val="a"></span>
       <span data-val="a"></span>
     </div>
     </div>
 
 
@@ -41,6 +42,10 @@
       });
       });
 
 
       looper(scope);
       looper(scope);
+
+      scope.aze[1].a = 'lol';
+
+      looper(scope);
     </script>
     </script>
   </body>
   </body>
 </html>
 </html>

+ 9 - 0
src/js/binder.js

@@ -80,6 +80,15 @@ function looper(scope) {
     let html = [];
     let html = [];
     // If data is an array (if not do nothing)
     // If data is an array (if not do nothing)
     if (data && Array.isArray(data)) {
     if (data && Array.isArray(data)) {
+      // If data is already computed back to the initial value
+      const defaultValue = el.querySelector('[data-looped]')
+      if (defaultValue)  {
+        el.innerHTML = defaultValue.innerHTML;
+      }
+
+      // Add the not computed value
+      html.push(`<div data-looped="${propName}" style="display: none">${el.innerHTML}</div>`);
+
       // Add info to replace value
       // Add info to replace value
       for (let i = 0; i < data.length; i++) {
       for (let i = 0; i < data.length; i++) {
         html.push(el.innerHTML.replace(/data-val="/g, 'data-index="' + i + '" data-val="'));
         html.push(el.innerHTML.replace(/data-val="/g, 'data-index="' + i + '" data-val="'));