gpt4 book ai didi

javascript - meteor JS : Auto-fill form with data from a collection (autoform)

转载 作者:行者123 更新时间:2023-11-28 07:00:33 25 4
gpt4 key购买 nike

我正在尝试更新与 this example 相同的数据,但我没有使用 afQuickField name="nameOfTheField,而是使用 afQuickFields。我尝试单独显示字段(就像他们在演示中所做的那样),但它也不起作用。浏览器日志显示正确的数据。

HTML enter image description here

JS

enter image description here

尝试使用字段名称和值属性进行相同的操作是可行的,但方法过于具体,在我的情况下并不理想

enter image description here

更新:表单类型更改为“更新”,但仍然不起作用

最佳答案

假设您有一个像这样的客户集合和架构:

lib/schema.js

Schemas = {};

Schemas.customerSchema = new SimpleSchema({
name: {
type: String,
index: 1,
unique: true
},
age: {
type: Number,
optional: true
}
});

Collections = {};

Customers = Collections.Customers = new Mongo.Collection("Customers");
Customers.attachSchema(Schemas.customerSchema);

您的更新表单可能如下所示:

<template name="customerUpdate">
{{#autoForm id="afUpdateDemo" type="update" collection=Collections.Customers doc=this}}
{{> afQuickFields schema="Schemas.customerSchema"}}
<div class="text-center">
<button type="submit" class="btn btn-primary">Update</button>
</div>
{{/autoForm}}
</template>

我正在将架构传递到 afQuickFields 中。这将为架构中的每个元素提供字段。如果您需要更有选择性地选择包含哪些字段,您还可以传递 fieldsomitFields 属性。我正在使用 doc=this,因为我在路由中设置数据上下文,但您可以继续使用 instanceData,如您所示,假设它是有效引用到文档(您没有显示足够的代码来了解该值的来源)。

我在 github 上放了一个示例应用程序:https://github.com/markleiber/so_32178232

关于javascript - meteor JS : Auto-fill form with data from a collection (autoform),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32178232/

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