Javascript 使用JSON的角度双向绑定?

Javascript 使用JSON的角度双向绑定?,javascript,angularjs,json,Javascript,Angularjs,Json,实际上,我的作用域中有一个JSON。每当ng模型得到更改时,我都需要更改JSON值。在下面的示例中,JSON具有具有属性(CuId、名称、数量、速率、金额)的行集。我必须将这些属性名与控件(文本框)绑定,比如ng model=CuId。因此,每当相应的属性值发生更改时,JSON都需要更新 请提供任何与此相关的例子,或建议我如何实现这一点 JSON: 你必须把整棵树放在ng模型中。像这样: <input type="text" ng-model="postJSON.collections.C

实际上,我的作用域中有一个JSON。每当ng模型得到更改时,我都需要更改JSON值。在下面的示例中,JSON具有具有属性(CuId、名称、数量、速率、金额)的行集。我必须将这些属性名与控件(文本框)绑定,比如ng model=CuId。因此,每当相应的属性值发生更改时,JSON都需要更新

请提供任何与此相关的例子,或建议我如何实现这一点

JSON:


你必须把整棵树放在ng模型中。像这样:

<input type="text" ng-model="postJSON.collections.Customer29Jan16.rowset.CuId" />

您必须将整个树放在ng模型中。像这样:

<input type="text" ng-model="postJSON.collections.Customer29Jan16.rowset.CuId" />

然后使用:

<input ng-model="rowset.CuId" />

然后使用:

<input ng-model="rowset.CuId" />

您已将
postData
添加到范围中,以便可以像这样绑定到单个属性

<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].CuId" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Name" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Quantity" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Rate" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Amount" />

您已将
postData
添加到范围中,以便可以像这样绑定到单个属性

<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].CuId" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Name" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Quantity" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Rate" />
<input ng-model="postJSON.collections.Customer29Jan16.rowset[0].Amount" />


正如其他答案所提到的,您需要使用整个树,直到要更改的属性。但是,他们没有提到,因为
行集
是一个数组,所以还必须指定要访问
行集
的哪个元素。使用类似于
ng model=“postJSON.collections.Customer29Jan16.rowset[0].CuId”的代码“

正如其他答案所提到的,您需要使用整个树,直到要更改的属性。但是,他们没有提到,因为
行集
是一个数组,所以还必须指定要访问
行集
的哪个元素。使用类似于
ng model=“postJSON.collections.Customer29Jan16.rowset[0].CuId”的代码“

你查过了吗。由于angular具有双向数据绑定,因此对模型所做的任何更改都将反映在json中。您只需正确访问该元素并将其作为ng模型添加到html中。使用类似于
ng model=“postJSON.collections.rowset[0].CuId“
@ViChU是的,我检查了,我使用双向绑定做了一个小示例,但我需要一个复杂的示例。您检查了吗。由于angular具有双向数据绑定,因此对模型所做的任何更改都将反映在json中。您只需正确访问该元素并将其作为ng模型添加到html中即可。使用类似于
ng model=“postJSON.collections.rowset[0].CuId“
@ViChU是的,我检查了,并使用双向绑定制作了一个小示例,但我需要一个复杂的示例。