使用 Json 对象更新时羊驼 setValue 不替换值
Alpaca setValue not replacing the value when updating with Json object
使用 Alpaca js 我正在尝试使用 setValue 来更改字段值
我创建了这个简单的示例,它是一个单一的输入表单,当单击 "update input" 按钮时
输入应更新为新值,"NEW VALUE"
知道为什么它不起作用吗?
$(document).ready(function(){
createForm("firstName","First Name","OLD VALUE","string");
});
function updateForm(){
alert(JSON.stringify($("#alpacaForm").alpaca().getValue(), null, " "));
$("#alpacaForm").alpaca().setValue('{"fieldName": "NEW VALUE"}');
}
function createForm(fieldName,fieldLable,fieldVal,fieldType){
$("#alpacaForm").alpaca({
"data": { fieldName: fieldVal },
"schema": {
"type": "object",
"properties": {
fieldName: {
"type": fieldType,
"title": fieldLable
}
}
}
});
}
<!-- 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="alpacaForm" ></div>
<button onclick="updateForm()">update input</button>
Form.setValue
应该传递一个对象。
$(document).ready(function() {
createForm("firstName", "First Name", "OLD VALUE", "string");
});
function updateForm() {
alert(JSON.stringify($("#alpacaForm").alpaca().getValue(), null, " "));
$("#alpacaForm").alpaca().setValue({"firstName": "NEW VALUE"});
}
function createForm(fieldName, fieldLable, fieldVal, fieldType) {
$("#alpacaForm").alpaca({
"data": {
[fieldName]: fieldVal
},
"schema": {
"type": "object",
"properties": {
[fieldName]: {
"type": fieldType,
"title": fieldLable
}
}
}
});
}
<!-- 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="alpacaForm"></div>
<button onclick="updateForm()">update input</button>
使用 Alpaca js 我正在尝试使用 setValue 来更改字段值
我创建了这个简单的示例,它是一个单一的输入表单,当单击 "update input" 按钮时
输入应更新为新值,"NEW VALUE"
知道为什么它不起作用吗?
$(document).ready(function(){
createForm("firstName","First Name","OLD VALUE","string");
});
function updateForm(){
alert(JSON.stringify($("#alpacaForm").alpaca().getValue(), null, " "));
$("#alpacaForm").alpaca().setValue('{"fieldName": "NEW VALUE"}');
}
function createForm(fieldName,fieldLable,fieldVal,fieldType){
$("#alpacaForm").alpaca({
"data": { fieldName: fieldVal },
"schema": {
"type": "object",
"properties": {
fieldName: {
"type": fieldType,
"title": fieldLable
}
}
}
});
}
<!-- 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="alpacaForm" ></div>
<button onclick="updateForm()">update input</button>
Form.setValue
应该传递一个对象。
$(document).ready(function() {
createForm("firstName", "First Name", "OLD VALUE", "string");
});
function updateForm() {
alert(JSON.stringify($("#alpacaForm").alpaca().getValue(), null, " "));
$("#alpacaForm").alpaca().setValue({"firstName": "NEW VALUE"});
}
function createForm(fieldName, fieldLable, fieldVal, fieldType) {
$("#alpacaForm").alpaca({
"data": {
[fieldName]: fieldVal
},
"schema": {
"type": "object",
"properties": {
[fieldName]: {
"type": fieldType,
"title": fieldLable
}
}
}
});
}
<!-- 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="alpacaForm"></div>
<button onclick="updateForm()">update input</button>