VmInputRadio.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace VberAdmin.Web.Models.Input;
  2. public class VmInputRadio : VmInputBase
  3. {
  4. public VmInputRadio(string name, string displayName) : base(name, displayName, VmInputType.RadioBox)
  5. {
  6. DefaultValue = "form-check-input";
  7. }
  8. public List<VmInputCheckBoxRadioItem> Items { get; set; }
  9. /// <summary>
  10. /// name,value , name,value 成对设置
  11. /// </summary>
  12. /// <param name="items"></param>
  13. /// <returns></returns>
  14. public VmInputRadio WithItems(params string[] items)
  15. {
  16. Items ??= new List<VmInputCheckBoxRadioItem>();
  17. for (int i = 0; i < items.Length; i++)
  18. {
  19. if (items.Length - 2 > 0)
  20. {
  21. Items.Add(new VmInputCheckBoxRadioItem(items[i], items[++i]));
  22. }
  23. }
  24. return this;
  25. }
  26. public VmInputRadio AddItems(params VmInputCheckBoxRadioItem[] items)
  27. {
  28. Items ??= new List<VmInputCheckBoxRadioItem>();
  29. foreach (var item in items)
  30. {
  31. Items.Add(item);
  32. }
  33. return this;
  34. }
  35. public VmInputRadio AddItems(List<VmInputCheckBoxRadioItem> items)
  36. {
  37. Items ??= new List<VmInputCheckBoxRadioItem>();
  38. Items.AddRange(items);
  39. return this;
  40. }
  41. }