简体   繁体   English

使用“ this”将相应的数据插入动态添加的行中

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

I am newbie to Angular js.'this' operator will be helpful, but no idea how to use it. 我是Angular js的新手,'this'运算符会有所帮助,但不知道如何使用它。

On Each First Column, user will input the data, and corresponding that data should be fetched. 在每个第一列上,用户将输入数据,并相应地应提取该数据。 Now data is fetched from php to Angular js, but how to push the data from angular js to that text box using "this" operator. 现在,数据已从php提取到Angular js,但是如何使用“ this”运算符将数据从Angular js推送到该文本框。

For eg: If 'Y' is entered then, X and Z should be push to textbox If 'Q' is entered then, P and R should be push to textbox. 例如:如果输入“ Y”,则应将X和Z推入文本框。如果输入“ Q”,则应将P和R推入文本框。 HTML: 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>

Angular Js: 角度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 machin.php

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

I am unable to sort this problem.Please help me.Thanks in advance. 我无法解决此问题。请帮助我。谢谢。

This should do the trick: 这应该可以解决问题:

  1. Don't use this, use $scope. 不要使用这个,使用$ scope。
  2. Change ng-value to ng-model 将ng-value更改为ng-model

HTML 的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>

Angular: 角度:

$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];
        });
    };

Here's a plunker with example. 这是一个例子。 I can't do the http request so I just resolve the promise. 我无法执行http请求,因此只能解决诺言。

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

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

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