cipchk / nz-schema-form

ng-zorro-antd form generation based on JSON-Schema
MIT License
40 stars 14 forks source link

model 给到 schema 后,再次序列化会导致 model给定的字段丢失 #41

Open liweitao92 opened 6 years ago

liweitao92 commented 6 years ago

Bug Report or Feature Request (mark with an x)


[ ] Bug report -> please search issues before submitting
[x] Feature request
[ ] Documentation issue or request

Reproduction link

image

Steps to reproduce

Schema


{
"span_label": 4,
"span": 8,
"properties": {
"email": {
"type": "string",
"title": "邮箱",
"format": "email",
"placeholder": "请输入邮箱,最多20个字符",
"maxLength": 20,
"debug": true
},
"name": {
"type": "string",
"title": "姓名",
"placeholder": "请输入姓名",
"description": "必须大写开头且3个字以上",
"minLength": 3,
"debug": true
},
"age": {
"type": "number",
"title": "年龄"
},
"remark": {
"type": "string",
"title": "描述"
},
"products": {
"type": "array",
"title": "产品清单",
"maxItems": 2,
"items": {
"type": "object",
"properties": {
"pn": {
"title": "产品名称",
"type": "string"
},
"num": {
"title": "件数",
"type": "number",
"minimum": 1,
"maximum": 1000
},
"price": {
"title": "金额",
"type": "number"
}
},
"required": ["pn", "num", "price"]
}
}
},
"button": {
"style": { "text-align": "center" },
"items": [
{
"label": "Send",
"id": "send",
"submit": true,
"offset": 4
},
{
"label": "Reset",
"id": "reset"
}
]
}
}
> Model
```json
{
    "email": "cipchk@qq.com",
    "id": "1",
    "sex": "1",
    "name": "zhangsan"
}

从服务器获取到的 json 字符串可能是很长的,可能很多属性都没有在Schema 中,通过 model 将值绑定到 Schema 后,在通过编辑表单得到的结果不会包含那些没有在Schema中定义的属性

例如


//服务端 json
{"username":"admin","email":"1@1.com","sex":"1"}

//Schema 中定义的属性 "username": { "type": "string", "title": " 用户名" }, "email": { "type": "string", "title": "邮箱" },

//最后通过表单获取到的 json {"username":"xxx","email":"xxx"}



## What is expected?
<!-- 期望的结果是什么 -->
根据传入的 model 值,在表单序列化 json 的时候,保留 model 原有的字段,进行部分字段的更改

## What is actually happening?
<!-- 实际的结果是什么 -->

表单序列化出的 json 不会保留 model 原有的 字段属性

## Environment
<!-- 环境 -->

<pre><code>
ng-alain version: X.Y.Z
Angular version: X.Y.Z
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] IE version XX
</code></pre>
liweitao92 commented 6 years ago

当然,如果后台 SQL 都是自己写的没啥问题,主要是现在很多 ORM 工具,比如 Spring 的 jpa 采用的 hibernate 非常典型

cipchk commented 6 years ago

的确如此,特别是在修改状态时,会有很多不可见属性。这个问题可能 nz-sf 逻辑判断有问题。我会核实一下。

cipchk commented 6 years ago

使用:

<nz-sf [(model)]="model"></nz-sf>