在AngularJS中创建一个下钻表单

Creating a drill-down form in AngularJS

本文关键字:一个 表单 AngularJS 创建      更新时间:2023-09-26

我试图使用AngularJS在web应用程序中创建一个提交表单,其中每个表单条目的选项依赖于对前一个表单条目的响应。为了简单起见,我希望将它们全部放在一个页面上,并且在填充前一个表单条目之前,进一步的表单项将显示为灰色,或者在验证前一个响应时弹出。我想这个概念可能有一个名字,但我一直在努力为相关的搜索结果找到正确的关键字来找到这个想法的例子或教程。这个概念叫什么?

下面是一个简化的表单示例,其中用户提交比赛结果。常量提供程序提供定义下拉选项的对象(例如allSports.team=['Basketball', Soccer', ...]),但是显示哪些选项取决于先前的用户输入(例如category=team)。

- What is the name of the tournament?
- What category of tournament sport is it? (drop down)
  - Team (yes)
  - Individual
- What sport is it? (drop down)
  - Basketball
  - Soccer (yes)
- How many games were played in the tournament? (text entry)
  - 3*
- For game 1, what was the name of the home team?
  - Cougars
- For game 1, what was the name of the away team?
  - Penguin
- Indicate which team won game 1:
  - Cougars (yes) 
  - Penguins
- (repeat for games 2-3)

提交按钮将tournament对象添加到tournaments对象数组中,类似于以下内容:

var tournaments = [
  { 'tourneyName' = 'Cougar Classic',
    'sportType' = 'Team',
    'sportName' = 'Soccer',
    'games' = [
      { 'teams' = [ 'Cougars', 'Penguins' ],
        'winner' = 'Cougars' },
      { 'teams' = [ 'Cougars', 'Penguins' ],
        'winner' = 'Penguins' },
      { 'teams' = [ 'Cougars', 'Penguins' ],
        'winner' = 'Cougars' }
      ]       
  },
  (next tournament)  
]

在web应用程序中,用户可以根据特定的标准搜索比赛(所有篮球比赛,企鹅获胜的足球比赛,所有个人运动等)

你能提供的任何资源或帮助,帮助我完成这样的事情,我将不胜感激。我非常熟悉Angular的基础知识和简单的表单提交,但在我所做的教程中,我还没有真正找到这种范围的东西。此外,我正在与angular-meteor一起工作,所以如果有任何专业人士有任何更具体的建议(相关软件包等),我将非常欢迎。

我想出了我正在寻找的概念的名称,称为"级联选择"。一旦我明白了这一点,我就能够找到一些有用的资源来完成这个任务。这里有一个例子。有趣的是,掌握正确的词汇是多么重要!

我发现angular也形式上完成了很多我一直在寻找的其他事情,比如可以集成级联,可以交互式地启用/禁用选项,等等。

我希望这个发现能帮助到其他人!