0

我正在开发一个包含表单页面的网络应用程序。

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

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

在每个 mandi中,我们都有namemandi_correspondent_detail。我们可以动态添加多个mandi_correspondent_detail

每个mandi_correspondent_detail 包含姓名和联系电话,我们可以通过数字字段动态添加多个号码。

如何在控制器中获取发布的数据,以便我能够将其插入到 mongodb 的模式中。

4

1 回答 1

0

您的视图应根据控制器的数据构建。这样你就可以使用two way binding,一切都会是最新的

例子:

在你的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

于 2015-04-02T14:56:55.803 回答