【发布时间】:2018-06-19 05:59:27
【问题描述】:
路线图:我有一个包含一行字段的表单并选择菜单。因此,当我在该表单中插入所有数据并按添加 (+) 按钮时,我希望该信息自动添加为表单下方定义的表中的一行。
我的表格:
<div class="form-inline"> <!-- location form -->
<div class="form-group">
<input type="text" placeholder="Landmark" ng-model="company.location.landmark"/>
</div>
<div class="form-group">
<input type="text" placeholder="Street 1" ng-model="company.location.street1"/>
</div>
<div class="form-group">
<input type="text" placeholder="Street 2" ng-model="company.location.street2"/>
</div>
<div class="form-group">
<input type="text" placeholder="City" ng-model="company.location.city"/>
</div>
<div class="form-group">
<select>
<option selected> State </option>
<option ng-model="company.location.state"> USA </option>
</select>
</div>
<div class="form-group">
<input type="text" placeholder="Zip" ng-model="company.location.zip"/>
</div>
<div class="form-group">
<select>
<option selected> Country </option>
<option ng-model="company.location.country"> Houston </option>
<option ng-model="company.location.country"> Dallas </option>
</select>
</div>
<div class="form-group">
<input type="text" placeholder="Latitude" ng-model="company.location.latitude"/>
</div>
<div class="form-group">
<input type="text" placeholder="Longitude" ng-model="company.location.longitude"/>
</div>
<div class="form-group">
<select>
<option selected> Type </option>
<option ng-model="company.location.type"> Permanent </option>
</select>
</div>
<div class="form-group">
<input type="button" class="btn btn-default btn-sm" value=" + " style="height: 25px;"/>
</div>
注意:在这个表格中,我可能有联系人列表和位置列表,所以也请更正我这样定义的 ng-model:
ng-model="company.location" and ng-model="company.location.contact"
TABLE 定义在表单的正下方:
<table class="table-striped"> <!-- location table -->
<tr>
<th>Landmark</th>
<th>Street 1</th>
<th>Street 2</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Country</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Type</th>
</tr>
<tr ng-repeat="location in company.location">
<td>{{location.landmark}}</td>
<td>{{location.street1}}</td>
<td>{{location.street2}}</td>
<td>{{location.city}}</td>
<td>{{location.state}}</td>
<td>{{location.zip}}</td>
<td>{{location.country}}</td>
<td>{{location.latitude}}</td>
<td>{{location.longitude}}</td>
<td>{{location.type}}</td>
</tr>
目前,当我在表单的单个字段中输入时,会在我输入时添加一个空行。但实际上我希望在单击表单的添加按钮时将表单添加到表格中。
最后,我希望你能帮助我的只是开始使用表单的添加按钮。太感谢了。
等待您的友好回复。
【问题讨论】:
-
你能创建一个 plunkr,它会帮助我们快速回答你的问题,否则我们需要付出很多努力。
-
@undefined 感谢您的回复。但我不知道如何创建 plunkr,它是什么。
-
你可以使用这个启动的angularjs plunkr添加示例代码来说明你的问题plnkr.co/edit/c3PIZnwxj5aZrkzrpC02?p=preview
-
@undefined plnkr.co/edit/XnuIiv?p=preview 请看看这个,是你想说的吗?
标签: javascript jquery angularjs forms