簡體   English   中英

使用“ this”將相應的數據插入動態添加的行中

[英]Insert corresponding data into dynamically added rows using “this”

我是Angular js的新手,'this'運算符會有所幫助,但不知道如何使用它。

在每個第一列上,用戶將輸入數據,並相應地應提取該數據。 現在,數據已從php提取到Angular js,但是如何使用“ this”運算符將數據從Angular js推送到該文本框。

例如:如果輸入“ Y”,則應將X和Z推入文本框。如果輸入“ Q”,則應將P和R推入文本框。 HTML:

<tr>
    <td><input type="text" ng-model="bot.Wo_Id" /></td>
    <td><input type="text" ng-click="acc1()" ng-value="b_code" /</td>
        <td><input type="text" ng-value="Pre_req" /></td>
        <td><a href ng-click="remove_bottle(bottle)">Remove</a></td>
</tr>
<tr>
    <td><a href ng-click="add_bottle()">Add</a></td>
</tr>

角度Js:

$scope.acc1 = function () {
    $http.get("machin.php", {
            params: {
                "W_id": this.bot.Wo_Id,
                "MC": "Machine"
            }
        })
        .success(function (response) {
            var values = response.split("@");
            $scope.b_code = ?
            $scope.Pre_req = ? // what should be code here
        });
};

machin.php

echo X."@".Z   //for input Y
echo P."@".R   //for input Q

我無法解決此問題。請幫助我。謝謝。

這應該可以解決問題:

  1. 不要使用這個,使用$ scope。
  2. 將ng-value更改為ng-model

的HTML

<tr>
    <td><input type="text" ng-model="bot.Wo_Id" /></td>
    <td><input type="text" ng-click="acc1()" ng-model="b_code" /</td>
        <td><input type="text" ng-model="Pre_req" /></td>
        <td><a href ng-click="remove_bottle(bottle)">Remove</a></td>
</tr>
<tr>
    <td><a href ng-click="add_bottle()">Add</a></td>
</tr>

角度:

$scope.acc1 = function () {
    $http.get("machin.php", {
            params: {
                "W_id": $scope.bot.Wo_Id,
                "MC": "Machine"
            }
        })
        .success(function (response) {
            var values = response.split("@");
            $scope.b_code = values[0];
            $scope.Pre_req = values[1];
        });
    };

這是一個例子。 我無法執行http請求,因此只能解決諾言。

https://plnkr.co/edit/f6EzxBlaFInJghNwsXaU?p=preview

暫無
暫無

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

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