gpt4 book ai didi

angularjs - Angular 模式形式默认值,隐藏值

转载 作者:行者123 更新时间:2023-12-02 22:45:19 29 4
gpt4 key购买 nike

我想构建一个表单(表单的一部分),它会产生以下输出:

{
...
offers: {
context: "http://schema.org",
minPrice: 3
}
...
}

问题是,context 应始终存在 - 用户可以操作的唯一字段是 minPrice。立即,一个具有值的隐藏字段浮现在脑海中。这是架构定义:

$scope.schema = {
...
offers: {
type: 'object',
properties: {
minPrice: {
type: 'number'
}
}
}
...
};

这里是表单定义:

$scope.form = [
...
{
key: 'offers',
type: 'fieldset',
items: [
{
key: 'offers.minPrice',
type: 'number'
},
{
key: 'offers.context',
type: 'hidden',
default: 'http://schema.org'
}
]
}
...
];

但是,观察生成的模型,很明显条目 context 不存在。我已经成功地将 type: 'hidden'defaulttabarray 结合使用,但我无法使用对象。我正在使用 angular-schema-forms0.8.13 版本 - 撰写本文时的最新版本。

如果有任何见解,我将不胜感激,谢谢。

最佳答案

您必须在该版本的架构中包含上下文及其默认值。

我预计您的问题与一个错误有关,该错误应该已在 v1.0.0 的 alpha 版本中修复

它应该适用于:

架构

{
"type": "object",
"properties": {
"offers": {
"type": "object",
"properties": {
"minPrice": {
"type": "number"
},
"context": {
"type": "string",
"default": "http://schema.org"
}
}
}
}
}

表单

[
{
"type": "fieldset",
"items": [
{
"key": "offers.minPrice",
"type":"number"
},
{
"key": "offers.context",
"type": "hidden",
"notitle": true
}
]
}
]

关于angularjs - Angular 模式形式默认值,隐藏值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41965082/

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