2016-11-18 66 views
1

我在AngularJS的應用程序中使用MEAN堆棧作爲我的前端。如何繁衍值表,在tablePayment value如在commacommission值作爲無comma所以如何乘這兩個值..... My Plunker對於實例:-1。交易: - 支付價值是1,925.10及佣金值3如何繁殖逗號價值,沒有逗號值例子: - 1,925.10*3 = 5775.3 ...如何在Angularjs中乘以兩個ng模塊值?

對於實例:-2。 Trasaction: - 支付價值是1,925.10及佣金值5如何繁殖逗號價值,沒有逗號值例子: - 1,925.10*5 = 9625.5 ...

我的HTML: -

<td >{{mani.payment }}</td> 

    <td >{{mani.commission}}</td> 

     <td >{{(mani.payment) * (mani.commission)}}</td> 

我的數據: -

{ 
    "_id": "5816f4fad0be79f809519f98", 
    "user": { 
    "_id": "57400c32bd07906c1308e2cf", 
    "displayName": "mani selvam" 
    }, 
    "__v": 0, 
    "created": "2016-10-31T07:38:34.999Z", 
    "remarks": "-", 
    "commission": "3", 
    "status": "pending", 
    "amt": "4000", 
    "cheque_currency": "Rs", 
    "cheque_value": "300", 
    "payment": "1,925.10", 
    "debitnote_no_payment": "3", 
    "supplier_name": "karikalan", 
    "buyer_name": "Manidesigns" 
}, 

{ 
"_id": "5816f4fad0be79f809519f98", 
"user": { 
    "_id": "57400c32bd07906c1308e2cf", 
    "displayName": "mani selvam" 
}, 
"__v": 0, 
"created": "2016-10-31T07:38:34.999Z", 
"remarks": "-", 
"commission": "5", 
"status": "pending", 
"amt": "2000", 
"cheque_currency": "Rs", 
"cheque_value": "300", 
"payment": "1,925.10", 
"debitnote_no_payment": "3", 
"supplier_name": "karikalan", 
"buyer_name": "Manidesigns" 
}, 

我創建Plunker供參考: - Plunker

+0

相關http://stackoverflow.com/a/29507259/1929187 – 0aslam0

+0

請看看我的plunker有人問我如何繁殖逗號值和無在表中的逗號值....這是不相關的問題,如果你呃解決方案請更新plunker以及解決方案謝謝,請幫助我們... –

回答

0

在你plunker,只需更換這行:

<td>{{(mani.payment) * (mani.commission)}}</td> 

有了這個其他:

<td>{{(mani.payment.replace(',','')) * (mani.commission.replace(',',''))}}</td> 

解決問題

0

當您迴應請求時,您確實應該將'1,925.10'更改爲1925.10。

1925.10是真正的價值,然而'1,925.10'是它的一種形式。

Make parseFloat convert variables with commas into numbers

function parseFloatIgnoreCommas(number) { 
    var numberNoCommas = number.replace(/,/g, ''); 
    return parseFloat(numberNoCommas); 
} 
+0

感謝您的寶貴答案,我得到的答案只有逗號1,925.10 ,所以你可以請更新plunker以及知道解決方案,請幫助我們.... –

+0

或只是將其轉換爲有效的數字 – xiaoyu2er

0

Y的個數ou傳遞乘法不是一個實際的數字,它是一個字符串檢查你的plunkr我已經更新它..或者請把它作爲一個數字在你的JSON中傳遞。

http://plnkr.co/edit/3zFrSqDWvE5pr3jgKO91?p=preview

<tr ng-repeat="mani in resultValue=(sryarndebitnote)"> 
     <td >{{$index + 1}}</td> 
      <td >{{mani.amt}}</td> 
      <td >{{mani.payment }}</td> 
      <td >{{mani.commission}}</td> 
      <td >{{(mani.payment) * (mani.commission)}}</td> 

      </tr> 
      <tr> 
      <td>sum</td> 
      <td>{{resultValue | sumOfValue:'amt'}}</td> 
      <td>{{resultValue | sumOfValue:'payment'}}</td> 
      <td></td> 
      <td></td> 
      </tr> 

或者

$scope.sryarndebitnote = [ 
{ 
    "_id": "5816f4fad0be79f809519f98", 
    "user": { 
    "_id": "57400c32bd07906c1308e2cf", 
    "displayName": "mani selvam" 
    }, 
    "__v": 0, 
    "created": "2016-10-31T07:38:34.999Z", 
    "remarks": "-", 
    "commission": "3", 
    "status": "pending", 
    "amt": "4000", 
    "cheque_currency": "Rs", 
    "cheque_value": "300", 
    "payment": 1925.10, // Change to number 
    "debitnote_no_payment": "3", 
    "supplier_name": "karikalan", 
    "buyer_name": "Manidesigns" 
}, 
{ 
"_id": "5816f4fad0be79f809519f98", 
"user": { 
    "_id": "57400c32bd07906c1308e2cf", 
    "displayName": "mani selvam" 
}, 
"__v": 0, 
"created": "2016-10-31T07:38:34.999Z", 
"remarks": "-", 
"commission": "5", 
"status": "pending", 
"amt": "2000", 
"cheque_currency": "Rs", 
"cheque_value": "300", 
"payment": 1925.10, 
"debitnote_no_payment": "3", 
"supplier_name": "karikalan", 
"buyer_name": "Manidesigns" 
} 
    ];