【问题标题】:TypeError: $(...).getValue is not a functionTypeError: $(...).getValue 不是函数
【发布时间】:2019-12-01 20:47:47
【问题描述】:

我有这个羊驼表格
我想获取表单的内容(用户输入的值)
所以我在羊驼网站上found an example
当按钮位于 this.getValue(); 中时,该示例工作正常;工作正常
但从外面我得到 TypeError: $(...).getValue is not a function
我做错了什么?

$("#field1").alpaca({
    "data": {
        "firstName": "John",
        "lastName": "McClane"
    },
    "schema": {
        "type": "object",
        "properties": {
            "firstName": {
                "type": "string",
                "title": "First Name"
            },
            "lastName": {
                "type": "string",
                "title": "Last Name"
            }
        }
    },
    "options": {
        "form": {
            "buttons": {
                "submit": {
                    "title": "Serialize - working fine....",
                    "click": function() {
                        var value = this.getValue();
                        alert(JSON.stringify(value, null, "  "));
                    }
                }
            }
        }
    }
});
        <!-- jquery -->
        <script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
 
        <!-- bootstrap -->
        <link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
        <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
 
        <!-- handlebars -->
        <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
 
        <!-- alpaca -->
        <link type="text/css" href="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.css" rel="stylesheet" />
        <script type="text/javascript" src="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.js"></script>
        
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>

<div id="field1" ></div>
<button onclick="console.log(JSON.stringify($('#field1').getValue(), null, '  '))">Serialize - Not working ....</button>

【问题讨论】:

    标签: alpacajs


    【解决方案1】:

    您应该在$('#field1')getValue() 之间添加alpaca()

    JSON.stringify($('#field1').alpaca().getValue()
    

    这是一个fiddle

    【讨论】:

    • 嗯我还有另一个问题,这是抛出 SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 JSON data
    • 您在我的小提琴中尝试过相同的代码吗?如果不能,你可以用你的代码创建一个新的吗?
    • 您的代码运行良好,我遇到了选择器问题,现在一切正常!!!非常感谢!
    猜你喜欢
    • 2012-07-22
    • 2020-06-29
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 2021-06-05
    • 2019-10-03
    • 2017-03-06
    相关资源
    最近更新 更多