簡體   English   中英

MeteorJS:使用集合中的數據自動填充表單(自動表單)

[英]MeteorJS: Auto-fill form with data from a collection (autoform)

我正在嘗試更新與本示例相同的數據,但不是使用afQuickField name="nameOfTheField我而是使用afQuickFields 。我嘗試了單獨顯示字段(就像在演示中一樣),它也不起作用。瀏覽器日志顯示正確的數據。

HTML 在此處輸入圖片說明

JS

在此處輸入圖片說明

使用字段名稱和值屬性嘗試相同的方法是可行的,但是方法太具體了,在我的情況下並不理想

在此處輸入圖片說明

更新:窗體類型更改為“更新”,仍然無法正常工作

假設您具有如下的客戶集合和模式:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM