2016-03-11 35 views
2

我正在使用ng-admin編寫管理管理。我遇到了下面的問題,有人能幫助我嗎?Ng-admin:如何根據用戶的選擇顯示不同的字段?

在我的creationView中,我想根據「type」字段的選擇顯示不同的字段(文本/視頻/圖片)。我如何做到這一點?

var articles = nga.entity('articles'); 
 
articles.creationView().fields([ 
 
     nga.field('type','choice') 
 
      .validation({ required: true }) 
 
      .choices([ 
 
       // 1: txt, 2: pic, 3: vid 
 
       { value: 1, label: 'Text'}, 
 
       { value: 2, label: 'Picture'}, 
 
       { value: 3, label: 'Video'}, 
 
      ]), 
 
     nga.field('txt','file') 
 
      .attributes({ placeholder: 'Write something... !' }), 
 
     nga.field('pic','file') 
 
      .label('Picture(.jpg|.png)') 
 
      .uploadInformation({ 'url': '/api/adminapi/uploadPicture', 'apifilename': 'pictures', 'accept': 'image/jpg,image/png'}), 
 
     nga.field('vid','file') 
 
     .label('Video(.mp4)') 
 
     .uploadInformation({ 'url': '/api/adminapi/uploadVideo', 'apifilename': 'video', 'accept': 'video/mp4'}), 
 

 
])

回答

1

我只是有一個全面的工作方法。這是使用.attributes(onclick,「return updateButton();」)爲nga.field(「類型」)。在updateButton()方法中,它將幫助檢查當前的「類型」字段值並使用DOM方法更改按鈕啓用和禁用。

但是,我仍然真的明白,如果這個要求可以在將來得到支持。用戶可以輕鬆製作UI控件。

2

Field Configuration文檔頁面介紹瞭如何使用 「模板」 字段配置要做到這一點:

模板(字符串|功能,templateIncludesLabel = FALSE) 支持模板()方法的所有字段類型,這使得可以輕鬆定製特定字段的外觀,而不犧牲本地功能。

...

要強制模板更換 整條生產線(包括標籤),作爲第二個參數 模板()調用傳遞true。這可以有條件地隱藏根據條目的屬性字段 非常有用:

post.editionView() .fields([ nga.field('category', 'choice') .choices([ { label: 'Tech', value: 'tech' }, { label: 'Lifestyle', value: 'lifestyle' } ]), nga.field('subcategory', 'choice') .choices(function(entry) { return subCategories.filter(function (c) { return c.category === entry.values.category; }); }) // display subcategory only if there is a category .template('<ma-field ng-if="entry.values.category" field="::field" value="entry.values[field.name()]" entry="entry" entity="::entity" form="formController.form" datastore="::formController.dataStore"></ma-field>', true), ]);

相關問題