【问题标题】:AlpacaJS: observer for dynamically added objects in array'sAlpacaJS:数组中动态添加对象的观察者
【发布时间】:2017-10-17 08:40:18
【问题描述】:

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

但是现在的问题是,如果我对静态字段集进行测试,这很容易,但我无法弄清楚我必须如何处理动态添加字段的观察者。

另外,我不确定是否可以选择解决相对字段而不是绝对字段。会容易得多,因为我必须始终在实际对象中设置值。

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

{
        "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
                    }
                }
            }
        }
    }

【问题讨论】:

  • 好的,我找到了我的问题。我只是使用了错误的路径结构。

标签: javascript jquery arrays observers alpacajs


【解决方案1】:

上例中使用的路径是

                 "options": {
            "items": {
                "fields": {
                    "services": {
                        "items": {
                            "fields": {
                                "category": {
                                    "events": {
                                        "change": function() {
                                            console.log(this.value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-22
    • 2020-08-21
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多