简体   繁体   English

从angular获取可编辑的数据行并将其发送到WEB API

[英]Get editable row of data from angular and sending it to WEB api

  1. How do I send to the 'save' event the complete object including what ever the user has typed in that row? 如何将完整的对象(包括用户在该行中键入的内容)发送到“保存”事件? For now, those 2 fields are always NULL no matter what I do. 现在,无论我做什么,这两个字段始终为NULL。

  2. (the temp comment) Where do I put this? (临时评论)我该放在哪里? I want to get the item data when the 'save' is clicked but I if I put it in there how do I refer to the specific row? 我想在单击“保存”时获取项目数据,但是如果我将其放入其中,如何引用特定行?

The example I started with used separate pages for list/edit so the problem I am having is how to combine the functionality into one page. 我开始的示例使用单独的页面进行列表/编辑,因此我遇到的问题是如何将功能组合到一个页面中。

var ListCtrl = function($scope, $location, Msa) {
    $scope.items = Msa.query();

    //temp: since I do not know how to get the value for specific row
    var id = 1;
    $scope.msa = Msa.get({id: id});

    $scope.save = function() {
        Msa.update({id: id}, $scope.msa, function() {
            $location.path('/');
        });
    }
};
<tbody>
    <tr ng-repeat="msa in items">
        <td>{{msa.PlaceId}}</td>
        <td>{{msa.Name}}</td>
        <td>
            <div class="controls">
                <input type="text" ng-model="msa.PreviousPlaceId" id="PreviousPlaceId">
            </div>
        </td>
        <td>
            <div class="controls">
                <input type="text" ng-model="msa.NextPlaceId" id="NextPlaceId">
            </div>
        </td>
        <td>
            <div class="form-actions">
                <button ng-click="save()" class="btn btn-primary">
                    Update
                </button><i class="icon-save"></i>
            </div>
        </td>
    </tr>
</tbody>      

It looks like it's in an ng-repeat so your scope isn't the same in the controller as in the ng-repeat. 看起来好像是在ng-repeat中,所以控制器中的作用域与ng-repeat中的作用域不同。

I think you can just send in the current msa element from items and then in the save method, loop through the original list matching the element that's sent in and then update the fields. 我认为您可以只发送项目中的当前msa元素,然后在save方法中循环遍历与所发送元素匹配的原始列表,然后更新字段。

<button ng-click="save(msa)" class="btn btn-primary">

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

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