【问题标题】:Angularjs get value from DynamoDBAngularjs 从 DynamoDB 中获取价值
【发布时间】:2019-05-11 16:18:33
【问题描述】:

我正在尝试从 DynamoDB 获取值,然后将该值分配给 ng-model 以显示该值。但是,数据始终为空。

Dynamodb table
 "meta_value": {
    "clause_note": "Note: good job!",
    "show_clause_note": true,
    "shown": true
  },

我收到了clause_note

Controller
            $scope.clause_note = null;
            $scope.item.remark = null;
            $scope.loading = true;
            $scope.getSettings = function () {
                customPrint.getAllSettings($scope.module).then(function (res) {
                    if ($scope.module) {
                        settings.then(function (stt) {
                            $scope.clause_note = stt['clause_note'];
                        });
                    } else {
                        alert('No module is specified!');
                    }
                }).finally(function () {
                    if ($scope.item.remark === $scope.clause_note) {
                        $scope.item.remark = '';
                        console.log($scope.clause_note);
                    }
                    else
                    {
                        $scope.clause_note = {show_clause_note: true};
                        $scope.clause_note = {shown: true};
                    }
                });
            };
            $scope.getSettings();

控制台日志返回为空。

html 
<ng-quill-editor ng-model="item.remark"></ng-quill-editor>

【问题讨论】:

  • 我认为您的数据在元值对象中
  • 这意味着我需要一个变量来获取元值对象?
  • 不,您必须遍历对象以获取表上的值

标签: angularjs laravel laravel-4 angularjs-scope amazon-dynamodb


【解决方案1】:

没有足够的信息来回答这个问题。 stt 变量的值是多少?如果meta_value 是该对象的属性,则此行:

$scope.clause_note = stt['clause_note'];

应该改为

$scope.clause_note = stt.meta_value.clause_note

如果你能告诉我,我会编辑这个答案:)

但代码还存在其他问题,使其更难维护。

例如,$scope.clause_note 似乎可以是字符串或对象。这使得代码的其他部分更难处理,因为它是什么类型并不总是很明显。

settings 的承诺似乎不知从何而来。也许在您的问题中显示它的来源是个好主意。此处也未使用来自getAllSettings 的响应。是不是搞错了?

也许你应该在发送getAllSettings 请求之前检查$scope.module 是否存在。如果它没有警报,则返回。这应该会删除您的 Promise 回调中的所有分支逻辑。

【讨论】:

  • 我明白了,stt 包含所有对象和值。因此,我只使用 stt[object][value];获得价值。谢谢提示。
猜你喜欢
  • 1970-01-01
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
  • 1970-01-01
  • 2013-08-11
相关资源
最近更新 更多