alpacajs - TypeError: $(...).getValue 不是函数
问题描述
我有这个 Alpaca 表单
我想获取表单的内容(用户输入的值)
所以我在 alpaca 网站上找到了一个示例
当按钮位于 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>
解决方案
推荐阅读
- flutter - 在 Flutter 中创建下拉菜单
- codeigniter - 从 2 多对多表中获取数据
- java - 在android中的水平进度条内显示百分比
- php - 格式异常(格式异常:意外字符(在字符 1)json
- c# - 有人可以解释这段 MVVM 代码吗
- ruby-on-rails - 如果嵌套属性为空,则从数据库中删除现有的嵌套属性记录
- ios - 反应原生 webview 缓存不适用于 IOS?
- nosql - DynamoDB 不按顺序显示项目
- entity-framework-6 - MapToStoredProcedures 不可用
- java - 如何识别 SQLite 数据库查询的异常?