Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

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

Open
liweitao92 opened this issue Mar 15, 2018 · 3 comments

Comments

@liweitao92
Copy link

liweitao92 commented Mar 15, 2018

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

{
    "email": "[email protected]",
    "id": "1",
    "sex": "1",
    "name": "zhangsan"
}

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

例如

//服务端 json
{"username":"admin","email":"[email protected]","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


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
@liweitao92
Copy link
Author

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

@cipchk
Copy link
Owner

cipchk commented Mar 15, 2018

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

@cipchk cipchk added the check label Mar 15, 2018
@cipchk
Copy link
Owner

cipchk commented Mar 15, 2018

使用:

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

@cipchk cipchk removed the check label Mar 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants