簡體   English   中英

從angular獲取可編輯的數據行並將其發送到WEB API

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

  1. 如何將完整的對象(包括用戶在該行中鍵入的內容)發送到“保存”事件? 現在,無論我做什么,這兩個字段始終為NULL。

  2. (臨時評論)我該放在哪里? 我想在單擊“保存”時獲取項目數據,但是如果我將其放入其中,如何引用特定行?

我開始的示例使用單獨的頁面進行列表/編輯,因此我遇到的問題是如何將功能組合到一個頁面中。

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>      

看起來好像是在ng-repeat中,所以控制器中的作用域與ng-repeat中的作用域不同。

我認為您可以只發送項目中的當前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