[英]How get dynamic JSON data using chekboxes in Angular JavaScript?
I am struggling so much and find so many links and articles but can't get solution.我很挣扎,找到了很多链接和文章,但找不到解决方案。 I have an array like that
我有一个这样的数组
$scope.cols=[
{"dpname":"partname","search":'',"qparam":''},
{"dpname":"partid","search":'',"qparam":''},
{"dpname":"partdesc","search":'',"qparam":''}
];
I am displaying array using ng-repeat as well as I repeat checkboxes also.我正在使用 ng-repeat 显示数组以及我也重复复选框。 When I click paricular check box one text box should open.
当我单击特定复选框时,应打开一个文本框。 The given ng-model value in text box is replaced by that particular check box
文本框中给定的 ng-model 值被该特定复选框替换
Here I attached my fiddle link which I tried: http://jsfiddle.net/soumyagangamwar/3dygzn8e/在这里,我附上了我尝试过的小提琴链接: http : //jsfiddle.net/soumyagangamwar/3dygzn8e/
I tweaked your files in this link我在此链接中调整了您的文件
jsfiddle.net/3dygzn8e/1/ jsfiddle.net/3dygzn8e/1/
basically what I did is the following:基本上我所做的是以下内容:
Have a look at this Fiddle看看这个小提琴
Although you have not clearly mentioned what you want in the question.虽然你在问题中没有明确提到你想要什么。 But if you want each item to have its own text box then the above fiddle should answer your question.
但是,如果您希望每个项目都有自己的文本框,那么上面的小提琴应该可以回答您的问题。
<span ng-if="displayName">
<input type="checkbox" id="searchName{{$index}}" ng-model="searchname[$index]" ng-change="changeColVisibility(col)">
</span>
<div ng-show="col.show">
<input type="text" ng-model="name">
<input type="button" value="submit" ng-click="setName(col)">
</div>
You should try not to use the index and should rather use more of the 2 way binding that comes with angular.您应该尽量不使用索引,而应该使用更多 angular 附带的 2 路绑定。 Both to show and hide the text box and to save data in models rather than creating loads of functions to do it.
既可以显示和隐藏文本框,也可以将数据保存在模型中,而不是创建大量函数来执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.