我之前问过这个问题,但没有得到答案。我有一个表单,通过填充它创建json对象并发布到server.this表单重复几次。 数据录入表格可以重复多次。
<div ng-repeat="office in offices">
<input type="text" ng-model="officeName">
<input type="text" ng-model="office.employee">
<input type="text" ng-model="office.employee">
<button ng-click="addOffice()">Add New Office</button>
</div>
假设我的对象是
public class FormData{
private List<Data> all;
}
public class Data{
private String officeName;
private List<Employee> list;
}
public class Employee{
private String name;
}
如何创建json对象并将从表单绑定获取的数据绑定到此对象? 以及如何创建表单输入数据?(如何设置模型)
答案 0 :(得分:4)
您可以这样做:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular-mocks.js"></script>
<div ng-app='app' ng-controller='myController'>
<button ng-click="addOffice()">Add New Office</button>
<div ng-repeat="office in offices" ng-if="offices">
<form name="officesForm" novalidate ng-submit="submitOffices()">
Company Name:
<input type="text" ng-model="office.name">
<div>
Employees:
<ng-form name="employeForm{{$index}}" ng-repeat="employee in office.employees">
<div>
<input type="text" ng-model="employee.name">
</div>
</ng-form>
<button type="button" ng-click="addEmployee(office)">Add Employee</button>
</div>
<button type="submit">submit</button>
</form>
</div>
<pre>{{ offices | json }}</pre>
</div>
Class.forName("com.mysql.jdbc.Driver");
沙盒iframe阻止它发布,因此它在plunker上。