2017-07-31 63 views
0

根據標題,我的問題是:我該如何重複( ng-repeat)預先選擇的項目,並讓用戶在以下步驟中輸入每個項目的數量,並在AngularJs中提交所有表單數據(現有重複項目+數量)?重複(ng-repeat)項目並讓用戶輸入每個項目的數量並提交AngularJs中的所有表單數據(現有重複項目+數量)

我想也許可以將$index添加到正在重複的項目?或者可能有更好更簡單的解決方案,我錯過了。

這就是我想實現:
後,用戶選擇產品添加至報價(沒有額外的輸入,例如數量),所選的項目,然後在接下來的步驟重複的「報價「視圖,客戶必須能夠爲每個報價項目輸入數量。所有數據必須在客戶端點擊NEXT時發送到控制器。

我通過重複表單中的每個項目(但禁用不希望客戶混淆的數據)並輸入數量來實現以下功能。但是這樣做的結果顯然是爲一個項目輸入的數量將所有QTY設置爲相同的數量。此外,在ng-click="next(quoteFormData)"傳遞的數據,僅包含單數量值,而不是所有的數據:

<div class="container-fluid" ng-show="showQuote"> 
    <form name="createNewQuoteForm" method="post" action="" class="form-horizontal" role="form"> 
     <div class="form-group" ng-repeat="item in quote"> 
      <div class="row"> 
       <div class="col-md-3"> 
        <input ng-model="quoteFormData.productId" type="text" class="form-control" id="" name="" placeholder="{{item.productId}}" ng-disabled="true"> 
       </div> 
       <div class="col-md-4"> 
        <input ng-model="quoteFormData.productName" type="text" class="form-control" id="" name="" placeholder="{{item.productName}}" ng-disabled="true"> 
       </div> 
       <div class="col-md-3"> 
        <input ng-model="quoteFormData.supplierName" type="text" class="form-control" id="" name="" placeholder="{{item.supplierName}}" ng-disabled="true"> 
       </div> 
       <div class="col-md-2"> 
        <input ng-model="quoteFormData.qty" type="text" class="form-control" id="" name="" placeholder="0"> 
       </div> 
      </div> 
     </div> 
    </form> 
    <div class="container-fluid"> 
     <button class="btn btn-primary" ng-click="next(quoteFormData)" ng-show="showNext">Next</button> 
     <button class="btn btn-warning" ng-click="cancel()">Cancel</button> 
    </div> 
</div> 

我一直在使用一個表來重複數據,並具有輸入域也嘗試了類似的方法數量,但我沒有設法得到任何這樣發送的數據。

+2

這可能是我見過的最詳細的問題的標題... –

+0

爲什麼你就不能綁定NG-模型,每個對象有一個屬性像'orderQty'?真的不清楚發送數據的具體問題。創建一個plunker演示 – charlietfl

+0

@charlietfl我正在引用步驟中嘗試此操作。但我認爲這是不行的,因爲重複項目中的'ng-disable'。此外,這個想法是,用戶可以簡單地點擊(使用電話)或點擊某個項目將其添加到報價中,然後在稍後階段讓客戶添加數量。 – onmyway

回答

0

發表我的評論作爲答案(對於任何人在未來運行這個問題)。

而不是綁定quoteFormData屬性(ng模型)嘗試綁定項目(引用項目)。然後在去NG點擊:下一個(報價)

<div class="container-fluid" ng-show="showQuote"> 
<form name="createNewQuoteForm" method="post" action="" class="form-horizontal" role="form"> 
    <div class="form-group" ng-repeat="item in quote"> 
     <div class="row"> 
      <div class="col-md-3"> 
       <input ng-model="item.productId" type="text" class="form-control" id="" name="" placeholder="{{item.productId}}" ng-disabled="true"> 
      </div> 
      <div class="col-md-4"> 
       <input ng-model="item.productName" type="text" class="form-control" id="" name="" placeholder="{{item.productName}}" ng-disabled="true"> 
      </div> 
      <div class="col-md-3"> 
       <input ng-model="item.supplierName" type="text" class="form-control" id="" name="" placeholder="{{item.supplierName}}" ng-disabled="true"> 
      </div> 
      <div class="col-md-2"> 
       <input ng-model="item.qty" type="text" class="form-control" id="" name="" placeholder="0"> 
      </div> 
     </div> 
    </div> 
</form> 
<div class="container-fluid"> 
    <button class="btn btn-primary" ng-click="next(quote)" ng-show="showNext">Next</button> 
    <button class="btn btn-warning" ng-click="cancel()">Cancel</button> 
</div> 

0

我做我的實現略有不同,但我預期的結果將是相同的。我在form-group本身做了綁定,並簡單地將數量字段綁定到ng-model="item.qty"。另外,我通過quote提交form時:

<div class="container-fluid" ng-show="showQuote"> 
    <form name="createNewQuoteForm" method="post" action="" class="form-horizontal" role="form"> 
     <div class="form-group" ng-repeat="item in quote" ng-model="item"> 
      <div class="row"> 
       <div class="col-md-3"> 
        <input type="text" class="form-control" id="" name="" placeholder="{{item.productId}}" ng-disabled="true"> 
       </div> 
       <div class="col-md-4"> 
        <input type="text" class="form-control" id="" name="" placeholder="{{item.productName}}" ng-disabled="true"> 
       </div> 
       <div class="col-md-3"> 
        <input type="text" class="form-control" id="" name="" placeholder="{{item.supplierName}}" ng-disabled="true"> 
       </div> 
       <div class="col-md-2"> 
        <input type="text" ng-model="item.qty" class="form-control" id="" name="" placeholder="0"> 
       </div> 
      </div> 
     </div> 
    </form> 
    <div class="container-fluid"> 
     <button class="btn btn-primary" ng-click="next(quote)" ng-show="showNext">Next</button> 
     <button class="btn btn-warning" ng-click="cancel()">Cancel</button> 
    </div> 
</div> 
相關問題