gpt4 book ai didi

javascript - 无法更新来自点国家的值

转载 作者:行者123 更新时间:2023-11-30 16:02:52 25 4
gpt4 key购买 nike

在我的页面上,我正在渲染表单,其中数据来自 api 调用数据看起来像:

    {
"id": 22,
"eventTypeId": 1,
"occuredDate": "2016-05-25T00:00:00",
"title": "event refresh",
"description": "check refresh table",
"studyId": 4,
"statusId": 5,
"severityId": 2,
"priorityId": 3,
"study.id": 4,
"study.name": "Study Y",
"status.id": 5,
"status.name": "Closed"
}

html:

    <form style="padding: 15px" ng-submit="submitForm()">
<div class="form-group row">
<div ng-repeat="k in rowKeys | filter: '!id'" ng-model="rowValue">
<label for="rowValue" class="col-sm-2">
{{k | hide:'.name'}}:</label>
<div class=" col-sm-2" >
<input class="form-control rowValue" id="rowValue" ng-model="rowData[k]" ng-disabled="isDisabled()"/>
</div>
</div>
</div>
<button type="submit" class="btn btn-default" ng-if="rowData" >Submit</button>
</form>

我的问题是当我编辑“标题”或“描述”等字段时,一切正常,但当我尝试编辑“study.name”或“status.name”等字段时,它只是刷新页面并不放任何更新。 Angular watch 工作正常,我在控制台中看到该值已更新,所以有人可以帮我找出我的错误吗?

我的提交功能:

$scope.submitForm = function() {

$scope.$watch('rowData', function(newValue, oldValue) {
console.log('being watched oldValue:', oldValue, 'newValue:', newValue);
}, true);

$http({
method : 'PUT',
url : $scope.globalUrl + $scope.id,
data : $scope.rowData //form
})
.then(function (res) {
return res;
})
.then(function (){
$('#table').bootstrapTable('refreshOptions', {
'url': $scope.globalUrl
});
})
};

我的加载函数

$scope.load = function (){
$http({
method: "GET",
url: $scope.globalUrl + $scope.id
}).then(function success(response) {
$scope.rowData = response.data;
}, function error(response) {
console.log("It has happend error in response")
});
}

最佳答案

当您的 key 中有一个点时,您需要使用括号表示法:

obj['study.name']

这是一个简单的例子:

https://jsbin.com/fihogu/1/edit?js,console

关于javascript - 无法更新来自点国家的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37448637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com