2014-09-29 11 views
10

की सरणी के साथ कस्टम AutoForm मैं एक SimpleSchema जो वस्तुओं की एक सरणी शामिल है:उल्का: वस्तुओं

Things.attachSchema(new SimpleSchema({ 
    name: { 
     type: String, 
     label: "Name", 
     max: 50 
    }, 
    fields: { 
     type: [Object], 
    }, 
    fields.$.name: { 
     type: String 
    }, 
    fields.$.amount: { 
     type: Number 
    } 
})) 

मैं कस्टम afEachArrayItem का इस्तेमाल कर रही बनाने के लिए करें कोशिश कर रहा हूँ, लेकिन मैं काम नहीं कर सकते हैं कि कैसे सरणी के भीतर प्रत्येक ऑब्जेक्ट के गुणों का संदर्भ लें।

मेरे टेम्पलेट इस तरह दिखता है (एचटीएमएल के साथ बाहर छीन):

{{#autoForm collection="things" id="myForm" }} 
    {{> afQuickField name='schemaName'}} 

    {{#afEachArrayItem name="fields"}} 

     {{> afFieldInput name="name"} 
     {{> afFieldInput name="amount"} 

    {{/afEachArrayItem}} 

{{/autoForm}} 

क्या करने के लिए "नाम" afFieldInputs में पारित किया जाना चाहिए?

उत्तर

12

सरणी के भीतर वस्तुओं के क्षेत्र का उपयोग करने के लिए, आप का उपयोग कर सकते हैं:

{{#autoForm collection="things" id="myForm" }} 
    {{> afQuickField name='schemaName'}} 

    {{#afEachArrayItem name="fields"}} 

     {{> afFieldInput name=this.current.name}} 
     {{> afFieldInput name=this.current.amount}} 

    {{/afEachArrayItem}} 

{{/autoForm}} 

मैं इस करता है, तो पता नहीं है:

this.current 

इसलिए उदाहरण के लिए ऊपर दिए गए, उपयोग ठीक करने के लिए ऐसा करने के लिए सही तरीका है, लेकिन ऐसा लगता है कि यह काम करता है।

+0

आप एक नई पंक्ति कैसे जोड़ते हैं? – ardochhigh

+1

डाउनवॉटेड: यह समाधान टेम्पलेट के हिस्से को छोड़ देता है जो नए तत्वों को सरणी में जोड़ने की अनुमति देता है। – rodamn

+0

@rodamn, आप टेम्पलेट का हिस्सा कैसे जोड़ेंगे जो नए तत्वों को सरणी में जोड़ने की अनुमति देता है? – bwobst

4

आप इतनी के रूप में जोड़ने के लिए/सरणी आइटम हटा बटन जोड़ सकते हैं:

{{#autoForm collection="things" id="myForm" }} 
    {{> afQuickField name='schemaName'}} 

    {{#afEachArrayItem name="fields"}} 

     <button type="button" class="btn btn-primary autoform-remove-item"><span class="glyphicon glyphicon-minus"></span></button> 
     {{> afFieldInput name=this.current.name}} 
     {{> afFieldInput name=this.current.amount}} 

    {{/afEachArrayItem}} 
    <button type="button" class="btn btn-primary autoform-add-item" data-autoform-field="fields"><span class="glyphicon glyphicon-plus"></span></button> 

{{/autoForm}} 

इस का उपयोग करेगा निर्मित बटन और AutoForm के लिए प्रतीक, इतनी के रूप में आवश्यक HTML संशोधित कर सकते हैं।

+0

जैसा कि आप वर्णन करते हैं, मुझे काम करने के लिए ऑटोफॉर्म-एड-आइटम नहीं मिल रहा है। क्या कोई अन्य पैराम सेट है जिसे सेट करने की आवश्यकता है? – LPG

+1

@ एलपीजी आपको सरणी को सही करने के लिए विशेषता डेटा-ऑटोफॉर्म-फ़ील्ड = "फ़ील्ड" सेट करने की आवश्यकता है (यानी _fields_ बदलें) – iiro

+0

धन्यवाद @iiro जो पूरी तरह से काम करता है। – LPG