2

我正在使用 Angular Schema Form 生成带有 JSON Schema 的表单我想在用户输入字符串 abc 时显示电子邮件文本字段,但是在输入 abc 后电子邮件文本字段永远不会出现。我认为问题出在变量名的范围条件中:“name=='abc'” 你能帮帮我吗?有代码

HTML

<html ng-app="myApp">
  <head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="bower_components/angular/angular.js" type="text/javascript"></script>
    <script src="bower_components/angular-sanitize/angular-sanitize.js" type="text/javascript"></script>
    <script src="bower_components/tv4/tv4.js" type="text/javascript"></script>
    <script src="bower_components/objectpath/lib/ObjectPath.js" type="text/javascript"></script>
    <script src="bower_components/angular-schema-form/dist/schema-form.js" type="text/javascript"></script>
    <script src="bower_components/angular-schema-form/dist/bootstrap-decorator.js" type="text/javascript"></script>
    <script src="js/app.js" type="text/javascript"></script>
  </head>
  <body ng-controller="myCtrl">
    <form sf-schema="schema" sf-form="form" sf-model="model"></form>
  </body>
</html>

应用程序.js

var myApp = angular.module("myApp", ['schemaForm']);
myApp.controller("myCtrl", function ($scope) {
    $scope.schema = {
        "type": "object",
        "title": "Comment",
        "properties": {
            "name": {
                "title": "Name",
                "type": "string"
            },
            "email": {
                "title": "Email",
                "type": "string"
            }
        }

    };

    $scope.form = [
        "name",
        {key: "email",
            condition: "name=='abc'"
        },
        {
            "type": "submit",
            "style": "btn-info",
            "title": "OK"
        }
    ];
    $scope.model = {};
});
4

1 回答 1

1

文档中,您可以看到您不能直接使用名称,因为条件适用于范围内的任何内容,而不仅仅是模型。因此,例如用“model.name=='abc'”替换“name”就可以了。在此处查看我的示例

于 2016-04-20T14:35:03.313 回答