在angularjs中处理动态添加的表单数据? [英] Handling dynamically added form data in angularjs?

查看:413
本文介绍了在angularjs中处理动态添加的表单数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含表单页面的Web应用程序.

I am working on an web app which contains form page.

mandi_detail:[{
        name: String,
        mandi_correspondent_detail:[{
            name:String,
            contact:[Number]
        }]       
    }]

这是模式的模型,我制作了一个ui页面,其中可以在 mandi_detail 中动态添加多个 mandi .

this is the model of a schema, i have made a ui page, in which in mandi_detail i can add multiple mandi dynamically .

在每个 mandi 中,我们有名称 mandi_correspondent_detail .我们可以动态添加多个 mandi_correspondent_detail .

In each mandi, we have name and mandi_correspondent_detail. we can add multiple mandi_correspondent_detail dynamically.

每个 mandi_correspondent_detail 由姓名和联系电话组成,我们可以通过数字字段动态添加多个电话号码.

Each mandi_correspondent_detail consist name and contact number and we can add multiple numbers by number field dynamically.

如何在控制器中获取发布的数据,以便能够将其插入mongodb的架构中.

how to get the posted data in controller so that i am able to insert it in schema in mongodb.

推荐答案

您的视图应根据控制器的数据进行构建.这样,您将使用two way binding,所有内容都将保持最新状态

Your view should be build according to your controller's data. This way you'll use two way binding and everything will be up to date

示例:

在您的controller

 $scope.myData=[];

 $scope.pushNew= function(){

    // build your newMandy object from the form existing in html
    // validate your form

    var newMandy={
      name: String,
      mandi_correspondent_detail:[{
         name:String,
         contact:[Number]
      }]       
    }

    $scope.myData.push(newMandy);
 }

在您的view

<div ng-repeat="data in myData">
    // your html structure here
</div>

// form for adding new mandy
<button ng-click="pushNew()">Add mandy details</button>

这样,您可以使用myData数组将所有内容存储在DB

This way you can use myData array to store everything in your DB

这篇关于在angularjs中处理动态添加的表单数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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