我正在做这样的事情:
document.properties["my:customProperty"] = getSomehowTheProperty(document);
my:customProperty
是一个字符串,在内容模型中有一些允许的值。
我如何从内容模型中获取允许的值,这样我就不必将它们存储在脚本中的 JavaScript 数组中?
或者我还能如何检查函数 getSomehowTheProperty
是否返回了允许的值?
我尝试用 try-catch 包裹它:
try {
document.properties["my:customProperty"] = getSomehowTheProperty(document);
document.save();
} catch (e) {
document.properties["my:customProperty"] = "Default Value";
document.save();
}
但看起来完整性已经过检查,错误是在执行脚本结束时抛出的,而不是在 try block 内。
谷歌搜索“alfresco js allowed values of node properties”和类似的查询没有给我任何结果。
最佳答案
为了获得此类信息,您必须使用 DictionaryService得到PropertyDefinition
在我的脑海中,你会想要做这样的事情:
QName customPropertyQ = QName.createQName("my:customProperty", namespaceService);
PropertyDefinition customPropertyT = dictionaryService.getProperty(customPropertyQ);
List allowedValues = customPropertyT.getConstraints();
那是在 Java 中,请参阅 this blog post有关如何从 JavaScript 使用 DictionaryService 的详细信息
关于javascript - Alfresco JavaScript - 如何获取节点属性的允许值列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17062556/