簡體   English   中英

使用ng-repeat進行json數組選擇

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

我做了這個頁面:

CODE (注意第二個叉子,在中間,而不是最后一個)

有兩個選擇:第二個是空的,並且自動完成,並帶有第一個選擇中選擇的選項的子數組。 這可行。

現在,這是我正在做的表。 實際上,這些行包含上面的兩個選擇。 我還將添加一個用於添加新行的按鈕,以便進行新選擇。 我試着迭代,但當然這是行不通的....在此更新你可以看到,在我的script.js添加了新的代碼(我提出的意見)。 我創建了一個數組來包含所有信息,一個函數添加了新行,一個函數刪除了行。 但是當然不行.....我在做什么錯?

特別是這是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);
 }

我的意思是重復整行,重復選擇。 一開始我有: <select></select> <select></select> <button></button> <button></button> 當我按下添加行時,我將復制<select></select> <select></select> <button></button> <button></button> 開拓新領域,新領域! 因此,迭代功能。

非常感謝您的建議!

伴侶,看這個:

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

您的代碼是:

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

我不明白的地方,該代碼現在似乎對我有用...更新的代碼插件: http ://plnkr.co/edit/A0Uh7jJUuJgWBBVKKjiU?p=preview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM