2017-06-07 130 views
1

这是动态创建的预期标记动态字段如何获得通过NG-模型

<textarea data-ng-model="cv.experience[content.title]"></textarea> 
<textarea data-ng-model="cv.experience[content.title]"></textarea> 
... 

这是我想达到

experience:{ 

    content:[ 
     { 
      header:String, 
      title:String, 
      start_date:Date, 
      end_date:Date, 
      location:String, 
      description:String 
     }, 
     { 
      header:String, 
      title:String, 
      start_date:Date, 
      end_date:Date, 
      location:String, 
      description:String 
     }, 
     .... 
    ] 
} 

如何JSON的样本我是否可以使用ng-model

+0

看看我的解决方案,看看这是你在找什么。 – mhodges

回答

1

您可以使用ng-repeat

这会为cv.experience.content中的每个对象创建一个textarea,然后将ng-model绑定到每个对象的title属性。我认为这就是你想要的,是的?

<textarea data-ng-model="content.title" data-ng-repeat="content in cv.experience.content"> 
</textarea> 
+0

感谢但ng-model'的性质是两种**数据绑定**,当我想更新任何'textarea'中的数据时,它显示所有'textarea'对我来说都是问题,我需要当用户输入数据给任何'textarea'都不会出现在所有'textarea'上,并且在重复字段上创建对象作为我的** JSON **结构 –

+0

@Kassambinary我不完全确定你的意思。如果你运行这个代码,它只会将每个textarea绑定到一个对象的title属性。如果您希望'ng-model'为您创建和构建JSON,那不是'ng-model'的作用。我建议阅读关于它的文档。 – mhodges