gpt4 book ai didi

javascript - $scope.model 属性的配置未定义

转载 作者:行者123 更新时间:2023-12-01 02:58:38 24 4
gpt4 key购买 nike

我正在 Umbraco 7 中实现内容选择器的 Controller ,我需要更改起始节点以匹配特定的内容节点。但是,当我使用内容选择器加载页面时,我收到一条错误消息:

"Cannot read property 'config' of undefined"

关于这段代码:

$scope.model.config.StartNodeId = 1083;
if ($scope.model.config.StartNodeId) {
options.startNodeId = $scope.model.config.StartNodeId;
}

我的整个 Controller :

angular.module("umbraco").controller("UIOMatic.FieldEditors.Pickers.ContentController",
function ($scope, $routeParams, $http, dialogService, entityResource, iconHelper) {

function init() {
if (!$scope.setting) {
$scope.setting = {};
}

var val = parseInt($scope.property.value);

if (!isNaN(val) && angular.isNumber(val) && val > 0) {
$scope.showQuery = false;

entityResource.getById(val, "Document").then(function (item) {
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.node = item;
});
}

$scope.openContentPicker = function () {
var d = dialogService.treePicker({

section: "content",
treeAlias: "content",
multiPicker: false,
callback: populate
});
};

$scope.model.config.StartNodeId = 1083;
if ($scope.model.config.StartNodeId) {
options.startNodeId = $scope.model.config.StartNodeId;
}

$scope.clear = function () {
$scope.id = undefined;
$scope.node = undefined;
$scope.property.value = undefined;
};

function populate(item) {
$scope.clear();
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.node = item;
$scope.id = item.id;
$scope.property.value = item.id;
}
};

if ($scope.valuesLoaded) {
init();
} else {
var unsubscribe = $scope.$on('valuesLoaded', function () {
init();
unsubscribe();
});
}
});

我尝试将起始节点 ID 更改为 1083,这正是我想要的,并且我可以很好地打开内容选择器,但它不允许我保存更改。它还允许多重选择,我已在配置对象中将其设置为 false。

这是作者提供的内容选择器的文档: http://uiomatic.readthedocs.io/en/stable/02.DefaultEditorViews/#content-picker

最佳答案

我认为您应该在为其对象赋值之前初始化 $scope.model。使用

$scope.model = {}

关于javascript - $scope.model 属性的配置未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46580617/

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