【发布时间】: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]);仍然没有定义