首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AlpacaJS:数组中动态添加对象的观察者

AlpacaJS:数组中动态添加对象的观察者
EN

Stack Overflow用户
提问于 2017-10-17 16:40:18
回答 1查看 395关注 0票数 0

我希望有人能给我一个提示。Ic创建了一个具有不同数组字段的表单。其中一个有两个下拉列表,第二个下拉列表中的条目取决于第一个条目的选择。THis应该很容易用观察者求解,在第一个值的选择发生变化后,只需加载第二个值即可。到目前为止,没有问题。

但现在的问题是,如果我测试静态字段集,这很容易,但我不知道如何处理动态添加的字段的观察者。

此外,我不确定是否有一个选项来处理相对字段而不是绝对字段。这会容易得多,因为我必须始终在实际对象中设置值。

这是一个小的小提琴设置https://jsfiddle.net/ygwuxrbk/

代码语言:javascript
复制
{
        "schema": {
            "title": "Erfassung",
            "type": "array",
            "items": {
                "title": "Account",
                "type": "object",
                "properties": {
                    "services": {
                        "type": "array",
                        "title": "Services",
                        "required": true,
                        "uniqueItems": true,
                        "items": {
                            "description": "Angebotenen Services des Anbieters",
                            "type": "object",
                            "id": "arr_item",
                            "properties": {
                                "category": {
                                    "type": "select",
                                    "title": "Service Kategorie",
                                    "required": true,
                                    "$ref": "#/definitions/categories"
                                },
                                "service": {
                                    "title": "Service",
                                    "type": "select",
                                    "enum": service["Beauty & Wellness"]
                                }
                            }
                        }

                    }
                 }
            },
            "definitions": {
                "categories": {
                    "enum":
                    categories
                },
            }
        },
        "options": {
            "fields": {
                "category": {
                    "type": "select",
                    "label": "Category",
                    "onFieldChange": function (e) {
                            console.log(this.getValue());
                    }
                }
            }
        },
        "form": {
            "attributes": {
                "action": "http://testcompany.com/echo.php",
                "method": "post"
            },
            "buttons": {
                "save": {
                    "title": "Save",
                    "click": function(e) {
                        alert(JSON.stringify(this.getValue()));
                        //this.submit(); // submit it via regular HTTP post
                        this.ajaxSubmit(); // submit via ajax
                    }
                }
            }
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2017-10-18 21:18:32

上面示例中使用的路径是

代码语言:javascript
复制
                 "options": {
            "items": {
                "fields": {
                    "services": {
                        "items": {
                            "fields": {
                                "category": {
                                    "events": {
                                        "change": function() {
                                            console.log(this.value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46785954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档