【问题标题】:Angularjs select "fake" model updatingAngularjs 选择“假”模型更新
【发布时间】:2015-11-11 07:07:16
【问题描述】:

我有一个带有下拉菜单的表单:

<select class="form-control input-sm" 
    ng-disabled="!editMode" 
    ng-model="case.LawyerParticipation.LawyerID" 
    ng-options="lawyer.ID as lawyer.Name for lawyer in lawyers" 
    ng-change="changed()"></select>

默认 LawyerID 值为“null”。 当触发更改事件时,“更改”函数会显示“case.LawyerParticipation.LawyerID”的值:

$scope.changed = function () {
     alert($scope.case.LawyerParticipation.LawyerID);
};

它表明模型按我的预期发生了变化。 $scope.case.LawyerParticipation.LawyerID 更改为我在下拉列表中选择的值。 下一步我想在服务器上发送这个值。我点击提交按钮并触发“updateCase”函数:

$scope.updateCase = function () {
    alert($scope.case.LawyerParticipation.LawyerID);

    $http.post("/case/update", $scope.case ).success(function (updatedCase) {
        $scope.case  = updatedCase;
    });
};

此功能中的警报告诉我没关系,并且“LawyerID”具有新值。 然后“发布”发生,在控制台中我看到发布在服务器上的模型有 LawyerID =“null”,它在服务器上也为 null!我做错了什么?为什么它是空的?

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    您的服务器代码中可能有一些拼写错误,请将您的服务器代码添加到问题中。

    $scope.updateCase = function () {
        alert($scope.case.LawyerParticipation.LawyerID);
    
        $http.post("/case/update", {data:$scope.case} ).success(function (updatedCase) {
            $scope.case  = updatedCase;
        });
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多