Kaynağa Gözat

recursive object set gives ability to set dom element subobjects like classList

Ivan Asmer 8 yıl önce
ebeveyn
işleme
26fb3971e5
1 değiştirilmiş dosya ile 15 ekleme ve 3 silme
  1. 15 3
      static/nb.js

+ 15 - 3
static/nb.js

@@ -73,14 +73,26 @@ function nbInit(a,b){
         }
     }
 
+    function recursiveObjectSet(item, value){
+        for (var key in value){
+            if (typeof value !== 'object'){
+                item[key] = value[key];
+            }
+            else {
+                recursiveObjectSet(item[key], value[key]);
+            }
+        }
+    }
+
     function syncToDOM(prop){
         nBind(function (item, $s, selector, value, key, thisByClass){
             value = typeof value === 'undefined' ? $s[selector] : value;
             var keyExists = typeof key !== 'undefined';
             if ((!item.children.length && !Array.isArray(value) && typeof value === 'object') || thisByClass){ //hash array on single leaf node -> set attrs on the tag
-                for (var key in value){
-                    item[key] = value[key];
-                }
+                recursiveObjectSet(item,value);
+                //for (var key in value){
+                    //item[key] = value[key];
+                //}
                 if (!thisByClass){
                     item.nbData = value;
                 }