我正在为Umbraco 7中的内容选择器实现一个控制器,我需要更改起始节点以匹配特定的内容节点。但是,如果我使用内容选择器加载页面,则会收到错误消息:
"无法读取属性' config'未定义"
关于这段代码:
$scope.model.config.StartNodeId = 1083;
if ($scope.model.config.StartNodeId) {
options.startNodeId = $scope.model.config.StartNodeId;
}
我的整个控制器:
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
答案 0 :(得分:2)
我认为你应该在为其对象赋值之前初始化$ scope.model。 使用
$scope.model = {}