AngularJS页面上的一对多映射 [英] OneToMany mapping on AngularJS page

查看:35
本文介绍了AngularJS页面上的一对多映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在具有Onetomany映射的AngularJS页面上编写输入字段?

How do we write input fields on AngularJS page which has Onetomany mapping?

User Class has Name and phone attributes and can have multiple phone numbers.

AngularJS code for fName input field

<input tabindex="10" style="width: 60%;" type="text" ng-model="ctrl.user.fName" placeholder="First Name">

''''''用于电话映射的AngularJS代码-因为这是一个OneToMany字段,所以我在User类中使用了List,现在我在AngularJS页面上有3个输入文本字段-因此我如何为同一个代码编写ng-model,对于第一个文本字段,我已经像下面这样声明了,但是第二个和第三个文本字段呢?如何为电话字段声明ng-model.

''''AngularJS code for phone mapping -as this is a OneToMany field so i have taken List in User class, now i have 3 input textfields on AngularJS page-so how do i write ng-model for the same, for first text field I have declared like below but what about second and third text fields-how to declare ng-model for phone field.

<input type="text" ng-model="ctrl.user.phone.phoneNumber" placeholder="Parking #">

推荐答案

因此我能够找到答案,而且令人惊讶的是,在任何门户网站上都找不到与此有关的材料.

so i was able to find the answer and surprisingly not much material is available on any portal regarding the same.

所以问题是如何在AngularJS和任何后端(如Springboot和Hibernate)中使用OneToMany映射.

so the question was how to use OneToMany mapping in AngularJS and any backend like Springboot with Hibernate.

Ex User具有直接的列,例如Name,age,DOB等,但可以说User与对象Contact(具有电话号码,电子邮件,紧急联系人等)具有一个完整的映射

Ex User has direct columns like Name, age, DOB etc but lets say User has onetomany mapping with an object Contact (which further has phonenumber, email, emergency contact etc)

在Agular中,我们可以将ng-bind直接放在ctrl.use.name之类的名称字段中,但对于phonenumber字段,它是通过以下方式指定的

In Agular we can directly put ng-bind on name field like ctrl.use.name but for phonenumber field, it was specified in below way

ctrl.user.contact [0].电话号码

ctrl.user.contact[0].phonenumber

请注意,现在在用户类中,您必须创建一个可以接受像这样的联系人数组的设置器-

Please note that, now in user class you have to make a setter which accept array of contacts like this-

公共无效setContact(Contact []联系人){....实现}

public void setContact(Contact[] contacts){....implementation}

所以现在在用户窗体上,我可以有多个联系人对象,这些对象将作为OneToMany关系持久化.

so now on user form i can have multiple contacts object which will be persisting as OneToMany relationship.

这篇关于AngularJS页面上的一对多映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆