SailsJS supplies a utility module called parasails, which defines two elements, <ajax-form> and <ajax-button> to allow user to create AJAX form easily.

In the most cases, the user could define a form as this in SailsJS

HTML

<ajax-form action="submitSomething"
:cloud-error.sync="cloudError"
:handle-parsing="handleParsingForm"
@submitted="submittedForm()">
<input type="text" v-model="someInput" >
<ajax-button type="submit" :syncing="syncing" class="btn btn-dark">Submit Something</ajax-button>
</ajax-form>

JS

parasails.registerPage('test-page', {
// ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
// ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
// ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
data: {
// Main syncing/loading state for this page.
syncing: false, // Form data
formData: { /* … */ }, // For tracking client-side validation errors in our form.
// > Has property set to `true` for each invalid property in `formData`.
formErrors: { /* … */ }, // Server error state for the form
cloudError: '',
}, // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
// ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
// ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
beforeMount: function() {
// Attach raw data exposed by the server.
_.extend(this, SAILS_LOCALS);
},
mounted: async function() {
//…
}, // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
// ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
methods: { handleParsingForm: function() {
var argins = this.formData; return argins;
}, submittedForm: async function() {
// Executed after submission.
}, }
});

Once user clicks the button, the two callback functions would be executed, the function handleParsingForm takes the data from the form, and submittedForm is the callback after success.

How about we want to do a dynamic form which sends the dynamically generated constant data from the server at page, and send it to the form again ?

Change the HTML to this.

<button type="submit" class="btn" v-on:click="setValue(someValue)">Submit</button>

Here we use default button and set the callback to event v-on:click, and once button was clicked, it runs the function setValue to call the JavaScript function. What we have to do in the JavaScript is add new function.

  methods: {

    setValue: function (someValue) {
this.formData.someValue = someValue;
}, }

So easy to pass the data into the form.

Thanks.

最新文章

  1. python 学习笔记十六 django深入学习一 路由系统,模板,admin,数据库操作
  2. 关于JavaScript lastIndexOf() 方法 w3school.com.cn写的不一定全对
  3. HTTPS传输协议原理
  4. UITableViewCell 设置圆角
  5. leetcode 40 Combination Sum II --- java
  6. redis学习(3)redis.conf配置文件详解
  7. Qt 控制watchdog app hacking
  8. uva 12096 The SetStack Computer
  9. 解决 SQL Server 耗尽内存的情况
  10. javascript事件捕获与冒泡
  11. linux之模拟简单登录的脚本
  12. C# .net基于Http实现web server(web服务)
  13. 运动框架实现思路(js)
  14. eclipse ide for java ee developers与eclipse ide for java developers有什么区别
  15. weex加入iconfont
  16. 听翁恺老师mooc笔记(16)--程序设计与C语言
  17. 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框)
  18. java开学考试有感以及源码
  19. 机器学习&amp;深度学习之路
  20. Bash Shebang 小结

热门文章

  1. Android版数据结构与算法(一):基础简介
  2. MVC设计模式思想及简单实现
  3. 一、Java 23 种设计模式简介
  4. C# 23种设计模式
  5. Mysql B+Tree原理
  6. Java提取URL某个参数的值
  7. Java并发-建立线程
  8. 常见形式 Web API 的简单分类总结
  9. 【Dubbo篇】--Dubbo框架的使用
  10. 《HelloGitHub》第 30 期