【问题标题】:Getting TypeError: Cannot set property 'scripts' of undefined获取 TypeError:无法设置未定义的属性“脚本”
【发布时间】:2018-07-24 19:09:56
【问题描述】:

我有以下 AngularJS 代码:

HTML:

<input type="text" class="form-control" id="repoInput" style="margin: 10px 0 10px 0" placeholder="Stored Procedures" ng-model="procedureInput" uib-typeahead="key for key in getScripts(selected.branchClone, selected.type) | filter:$viewValue | limitTo:10" typeahead-on-select='addStoredProcedure($item, selected);procedureInput = "";' typeahead-loading="templateLoading" typeahead-wait-ms="100" />

$scope.getScripts = function (repo, template) {
items.then(function (payload) {
            $scope.repos[template] = template;
            $scope.repos[template][repo] = repo;
            console.log($scope.repos[template]);
            console.log(repo);
            console.log($scope.repos[template][repo]);
            $scope.repos[template][repo]["scripts"] = payload.data.value;
            deferred.resolve(payload.data.value
                .map(function (x) {
                    return x["path"];
                }));
        });
}

我确实有 template 变量和 repo 变量的值。但是,我仍然在

上遇到错误

$scope.repos[template][repo]["scripts"] = payload.data.value;

TypeError:无法设置未定义的属性“脚本”

【问题讨论】:

  • 显示定义 repo 的代码。这可能是关键。
  • 抱歉,刚刚更新了我的问题。
  • console.log 输出什么? repo 是一个对象吗?
  • repo 的类型是什么?它似乎是一个对象,不能存储在地图结构中。
  • 对于 3 个控制台日志语句,我得到以下输出:数据库、主控、未定义。如您所见,我得到了 repo 的价值,但对于 console.log($scope.repos[template][repo]); 仍然没有定义

标签: angularjs typeerror


【解决方案1】:

我认为你需要重新审视你是如何使用括号表示法的。我认为您可能正在寻找 $scope.repos[‘template’] = template 和类似的东西来分配您的角色。 templaterole中存储的数据是什么形状的?

【讨论】:

    猜你喜欢
    • 2015-09-09
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    相关资源
    最近更新 更多