瀏覽代碼

Proof Of Concept fixes

Ivan Asmer 4 年之前
父節點
當前提交
01b38b55f5
共有 2 個文件被更改,包括 6 次插入7 次删除
  1. 4 4
      example/src/App.js
  2. 2 3
      src/index.js

+ 4 - 4
example/src/App.js

@@ -37,9 +37,9 @@ const Category = ({category:{name, _id}, children}) =>
     {children}
 </div>
 
-const Categories = ({children}) => 
+const Categories = ({children, data}) => 
 <div style={{border: '2px solid', paddingLeft: '20px'}}>
-    <h1>categories</h1>
+    <h1>categories({data && data.length})</h1>
     {children}
 </div>
 
@@ -74,7 +74,7 @@ const MetaTest = () => {
 
     return (
         <MetaPlate data={data}>
-            <Categories>
+            <Categories prop='data'>
                 <Category prop="category" keyDataKey="_id">
                     <Goods sourceDataKey="goods"> 
                         <Good prop="good" keyDataKey="_id">
@@ -83,7 +83,7 @@ const MetaTest = () => {
                             </div>
                         </Good>
                     </Goods>
-                    <Categories sourceDataKey="subCategories" >
+                    <Categories sourceDataKey="subCategories" prop='data'>
                         <Category prop="category" keyDataKey="_id" />
                     </Categories>
                 </Category>

+ 2 - 3
src/index.js

@@ -11,9 +11,8 @@ export const MetaPlate = ({ data, children }) => {
           if (meta instanceof Array) meta = meta[0];
           const Render = meta.type
           if (!meta.props.children) return <Render {...buildProps(data, meta)} />
-          return data.map(d => 
-              <Render {...buildProps(d, meta)}>
-                  {build(d, meta.props.children)}
+          return  (<Render {...buildProps(data, meta)}>
+              {data.map(d => build(d, meta.props.children))}
               </Render>
           )
       }