简体   繁体   English

使用ng-repeat进行json数组选择

[英]Use ng-repeat for a json array selection

I did this page: 我做了这个页面:

CODE (watch the second Fork, in the middle, not the last one) CODE (注意第二个叉子,在中间,而不是最后一个)

that there are two selection: the second one is empty and auto complete with a subarray of the option chosen in the first select. 有两个选择:第二个是空的,并且自动完成,并带有第一个选择中选择的选项的子数组。 This works. 这可行。

Now, this is for a table that I'm doing. 现在,这是我正在做的表。 In fact the rows contain the two selection above. 实际上,这些行包含上面的两个选择。 I will add also a button for ADD new line, so with new selection. 我还将添加一个用于添加新行的按钮,以便进行新选择。 I've tried to iterate, but of course it doesn't work.... In this update THIS you can see that in the script.js i've added new code (i made comments). 我试着迭代,但当然这是行不通的....在此更新你可以看到,在我的script.js添加了新的代码(我提出的意见)。 I've created one array to include all the info, one function to add new line and one function to delete line. 我创建了一个数组来包含所有信息,一个函数添加了新行,一个函数删除了行。 But of course it doesn't work....... what I am doing wrong? 但是当然不行.....我在做什么错?

In particular this is the new lines of js' code: 特别是这是js代码的新行:

 $scope.allInfo = [
  {
     "Product ID" : $scope.selectedProduct.id,
     "Product Nome" : $scope.selectedProduct.nome,
     "Product Codice": $scope.selectedProduct.codice,
     "Lot ID" : $scope.selectedLot.id,
     "Lot Value" : $scope.selectedLot.value
  }   
 ];

$scope.foods = [
 {
  "select1": "",
  "select2": ""
 }
]


$scope.newLine = function () {
  var itemToAdd = { "select1": "", "select2": ""};
 $scope.allInfo.push(itemToAdd);
}

$scope.removeLine = function (itemIndex) {
  $scope.foods.splice(itemIndex, 1);
 }

I mean to repeat the whole line, repeat the select. 我的意思是重复整行,重复选择。 At the beginning i have: <select></select> <select></select> <button></button> <button></button> . 一开始我有: <select></select> <select></select> <button></button> <button></button> When i press add line, i would to duplicate <select></select> <select></select> <button></button> <button></button> . 当我按下添加行时,我将复制<select></select> <select></select> <button></button> <button></button> Make completely a new line, with new field! 开拓新领域,新领域! So iterate the function. 因此,迭代功能。

Thank you very much in advice! 非常感谢您的建议!

mate, watch this : 伴侣,看这个:

 $scope.newLine = function () {
var itemToAdd = { "select1":   $scope.selectedProduct, "select2": $scope.selectedLot};
    $scope.allInfo.push(itemToAdd);
}

your code was : 您的代码是:

$scope.newLine = function () {
var itemToAdd = { "select1": , "select2": ""};
$scope.allInfo.push(itemToAdd);
}

which I did not understand, the code now seems working for me... updated code plunker: http://plnkr.co/edit/A0Uh7jJUuJgWBBVKKjiU?p=preview 我不明白的地方,该代码现在似乎对我有用...更新的代码插件: http ://plnkr.co/edit/A0Uh7jJUuJgWBBVKKjiU?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM