как отправить объект из html ng-repeat в функцию js - PullRequest
0 голосов
/ 08 ноября 2019

Я получаю данные из базы данных и помещаю их в область видимости, а затем повторяю эти данные с помощью ng-repeat в html. то, что я пытаюсь сделать, это отправить выбранный объект, когда пользователь установит флажок, чтобы получить другие данные, например, на основе идентификатора. я попытался использовать ng-модель и ng-change на флажке, но он отправляет только true или false.

HTML

<div id="frame" class="widget-content" style="height:50vh; overflow:auto;">
    <table  style="font-size: 12px;display: inline-block;">
        <thead>
            <tr>
                <th>Check</th>
                <th>Group Code</th>
                <th>Group Name</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="g in Groups | unique : 'Group_code'"
                ng-click="showInEdit(g)"
                ng-class="{selected:g === selectedRow}">
                <td><input type="checkbox" ng-model="g"
                           ng-true-value="g" ng-change="Getrequest2(g)"/>
                <td>{{g.Group_code}}</td>
                <td>{{g.group_name_latin}}</td>**
            </tr>
        </tbody>
    </table>
    <table  style="font-size: 12px; float: left;">
        <thead>
            <tr>
                <th>Check</th>
                <th>Item Code</th>
                <th>Item Name</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="i in items | unique : 'Item_code'"
                ng-click="showInEdit(i)"
                ng-class="{selected:i === selectedRow}">
                <td><input type="checkbox" />
                <td>{{i.Item_code}}</td>
                <td>{{i.ITEM_NAME_LATIN}}</td>
            </tr>
        </tbody>
    </table>
</div>

angularjs

$scope.Getrequest1 = function (g) {
    //console.log(g);
    $scope.typecd = g.TypeCode;
    $scope.ShowLoading('slow');
    LOASrv.GetGroup("LOAApprovalSetup/GetGroup" +
                    "?typ=" + g.TypeCode +
                    '&hospid=' + $scope.hospitalid + 
                    '&userky=' + $scope.userkey
    ).then(function (response) {
        $scope.Groups = (response.data);
        $scope.HideLoading('slow');
    })
}

$scope.Getrequest2 = function (i) {
    console.log(i);
    $scope.ShowLoading('slow');
    LOASrv.GetItem("LOAApprovalSetup/GetItem" + 
                   "?typ=" + $scope.typecd + 
                   '&hospid=' + $scope.hospitalid + 
                   '&userky=' + $scope.userkey +
                   '&groupcd=' + i
    ).then(function (response) {
        $scope.items = (response.data);
        $scope.HideLoading('slow');
    })
}

1 Ответ

0 голосов
/ 09 ноября 2019

Вы назначаете объект 'g' для флажка ng-model.

Это изменяет значение 'g' с объекта на логическое при выборе флажка.

Вот почему вы получаете true / false

Измените ng-model=“g.someBooleanName” и попробуйте

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...