2014-11-05 107 views
3

我有一些鏈接架構,並試圖從主架構的窗​​體訪問子模式的屬性。我知道這是一口。代碼可以幫助:流星autoform訪問嵌套屬性

//js 
Collection = new Meteor.Collection('collection'); 
Schemas = {}; 
Schemas.secondary = new SimpleSchema({ 
    unitType: { 
     type: String, 
     autoform: { 
     type: 'select', 
     options: //function with all the options 
    } 
    } 
}); 

Schemas.primary= new SimpleSchema({ 
    name: { 
     type: String, 
    }, 
     units: { 
     type: [ Schemas.secondary ] 
    } 
}); 

Collection.attachSchema(Schemas.primary); 


//HTML 
{{#autoForm collection="Collection" id="someId" type="insert"}} 
    {{> afQuickField name='name'}} // this works 
    {{> afQuickField name='units'}} // this works 
    {{> afQuickField name='units.unitType'}} // this doesn't work :-(
{{/autoForm}} 

我這樣做的原因是因爲在二級架構等性能,我想有條件地顯示的基礎上,選擇框的值。我也嘗試在窗體中放置一個窗體,然後運行{{#each afFieldNames name='"units"}},但那也不是很有效。它不是僅給出單位中包含的字段(即輔助模式),而是循環遍歷主要和次要的所有字段。

想法?我沒有結婚這種模式,但我想不出另一種方式。

再次感謝所有。 db

+0

嘗試'{{> afQuickField名= 'units.1.qty'}} {{> afQuickField名= 'units.1.unitType'}} ' – juanpastas 2014-11-05 04:33:21

+0

的答案是爲您繼承的每個模式選項創建自定義子模板。我會稍微張貼一個fildde。 – 2014-11-05 20:13:09

回答

0

我自己也有這個問題。

給這個一去

{{> afQuickField scope='units.unitType' name='units.unitType'}} 

如果你在轉儲你修正你之前提交鉤子,你應該能夠看到成功填補了子文檔

AutoForm.hooks({ 
    someId: { 
    before: { 
     'insert': function(modifier) { 
     console.log(modifier); 
     } 
    } 
    } 
}); 

讓我知道,如果這個工程您!

一切順利, 埃利奧特