简体   繁体   English

如何使用 Angular JavaScript 中的 chekboxes 获取动态 JSON 数据?

[英]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:基本上我所做的是以下内容:

  1. add a new column to the array called ischeched and default it to false.向名为 ischeded 的数组添加一个新列,并将其默认为 false。 this represent the checkbox check state这代表复选框检查状态
  2. bind the checkbox to col.ischecked将复选框绑定到 col.ischecked
  3. I changed the textbox ng-show condition to be ng-show="col.ischecked"我将文本框 ng-show 条件更改为 ng-show="col.ischecked"

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.

相关问题 如何使用动态数据使用高图获取角度的柱形图 - How to get column chart in angular using highcharts using dynamic data 如何使用 javascript 在数组中获取动态 JSON object 的索引 - How to get index of a dynamic JSON object in an array using javascript 如何在 angular 中传递 Javascript 变量(JSON 数据)以加载表中的动态数据 - How to pass Javascript variable (JSON Data) in angular for loading dynamic data in the table 使用JavaScript遍历动态JSON数据 - Looping through dynamic JSON data using javascript 如何使用动态数据创建动态按钮并在按钮单击角度时获得动态值 - How to create a dynamic button using dynamic data and get dynamic values on the button click in angular 如何使用Typescript / Javascript / Angular 4过滤JSON数据? - How to filter JSON data using Typescript / Javascript / Angular 4? 如何在 Angular 6 中使用异步获取 JSON 对象中的数据集合? - How to get data collections within the JSON Object using async in Angular 6? 如何使用jQuery从Angular服务获取JSON数据 - how to get json data from a angular service using jquery 如何在Javascript中使用动态数据获取JSON数组? - How to fetch JSON array with dynamic data in Javascript? 如何使用Angular JS获取json数据并构造模式 - How to get json data and construct a modal using Angular JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM