gpt4 book ai didi

javascript - 有规范的 meteor.js 表单包吗?

转载 作者:可可西里 更新时间:2023-11-01 01:33:27 26 4
gpt4 key购买 nike

是否有一个被认为是规范的表单包或一个可能类似于最终会成为核心的任何表单包?

在我的搜索中,我根据事件、吞吐量和文档(但可能还有其他)提出了两个主要竞争者:

如果有人看过这两种方法,您能否评论一下为什么或在哪里可以使用其中一种与另一种?

最佳答案

由于这个问题还没有得到解答,我将插话说“为什么你应该自己做”的论点。

表单既是 DOM 的显示又是验证。我认为 Meteor 对两者的工具都足够好,不需要在它们之间进行另一个抽象。

想想 meteor 给你带来了什么:你可以为你的对象编写一个类,它本身理解所有的验证和规则。不是通用的,“必须是数字方式”,而是以它们存在的复杂方式(必须是质数?)。你可以编写这个类,它可以在客户端和服务器上运行。您应该始终在客户端和服务器上进行验证。验证库如雨后春笋般涌现,因为客户端和服务器(至少)是两种不同的语言。 Node/Meteor 到处都是 JS。

为什么不用这个很棒的功能呢?不要将验证码放在多个地方。将您的数据提供给您的对象,让它在客户端(和服务器)接受或拒绝它。

例如,我通过结合自己的模板和辅助函数来创建每个文本元素:

表格

{{label_text fname='name' title='Agent Name' placeholder='Formal Name' collection='agent'  passthrough='autofocus=autofocus ' }}
{{label_text fname='agentInCharge' title='Agent In Charge' placeholder='Owner' collection='agent' }}
{{label_text fname='phone' title='Phone Number(s)' placeholder='Include Area Code'collection='agent' }}
{{>gps }}

模板

<template name='label_text'>
<div class="row">
<label class="large-3" for="{{fname}}_{{_id}}">{{title}}</label>
<div class="large-8">
<input name="{{fname}}"
id='{{fname}}_{{_id}}'
class="{{fname}}"
value="{{value}}"
data-original="{{value}}"
placeholder="{{placeholder}}"
type="{{type}}" {{passthrough}} />
</div>
</div>
</template>

和一些 helper :

generateField = (options) ->
options.hash.value = options.hash.value or this[options.hash.fname]

# allow for simple params as default
options.hash.title = options.hash.title or options.hash.fname
options.hash.template = options.hash.template or "label_text"
options.hash.placeholder = options.hash.placeholder or options.hash.title
options.hash.type = options.hash.type or 'text'

new Handlebars.SafeString(Template[options.hash.template](options.hash))



Handlebars.registerHelper "label_text", (options) ->
options.hash.collection = options.hash.collection or 'generic'
generateField.call this, options

Handlebars.registerHelper "label_text_area", (options) ->
options.hash.collection = options.hash.collection or 'generic'
options.hash.template = "label_text_area"
options.hash.rows = options.hash.rows or 3
options.hash.columns = options.hash.columns or 40
generateField.call this, options

Handlebars.registerHelper "switch", (options) ->
options.hash.template = "switch"
options.hash.em = options.hash.em || 7
generateField.call this, options

然后我向客户端对象发送数据,看看它是怎么想的。

关于javascript - 有规范的 meteor.js 表单包吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18712225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com