【问题标题】:Meteor (0.9.0.1): Using Helper with autoform to update a record for multiple usersMeteor (0.9.0.1):将 Helper 与 autoform 一起使用来更新多个用户的记录
【发布时间】:2014-09-05 22:36:16
【问题描述】:

我正在建立我的管理区域。我认为让多个管理员用户每个都可以访问相同的数据会很有用。我正在使用这个roles package

我正在使用 autoform 生成表单,因此当以“AdminA”身份登录时,该用户在表单中输入一个值并提交,然后记录存储在 AdminA 的帐户下。 AdminB 然后登录,但看不到表单上的值,因为该用户无权访问 AdminA 的帐户。我需要一种告诉 autoform 更新一条记录的方法。

下面的代码是我想要实现的。任何人都可以建议我需要做什么才能使其正常工作吗?我已经查看了 autoform 文档,但我并不完全确定。

表单输入框在渲染时会有点像这样:

<input type="text" name="VehiclePrice" value="10000" />
<input type="hidden" name="_id" value="LEXANiNZtunFPfBea">

模板:

<template name="VehiclePrice">
 {{#if submitted}}
    {{> quickForm collection="VehiclePrice" omitFields="createdBy" doc=editingDoc id="VehiclePrice" type="update"}}
 {{else}}
    {{> quickForm collection="VehiclePrice" omitFields="createdBy" id="VehiclePrice" type="insert"}}
 {{/if}}
</template>

助手:

Template.VehiclePrice.helpers({ 
 VehiclePrices: function () {
   return VehiclePrice.find().map(function (c) {
     return {price: c.price, _id: c._id};
   });
 }
});

关系将是多个管理员用户与一条记录 (*:1)

有什么想法吗?

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    通过发布车辆集合,您可以以编程方式确定谁可以访问数据,以及发布什么数据集。查看 Meteor 发布文档 (http://docs.meteor.com/#meteor_publish)。

    设置集合后,您可以通过发布命令确定要发布哪些数据集,例如:

    Meteor.publish("vehicleInfo", function () { if ( this.role == "admin" ) return Vehicle.find(); else return Vehicle.find({some subset of the data, or none at all (false)}); });

    【讨论】:

    • 我已经更新了问题,我觉得我说得不够清楚。
    【解决方案2】:

    原来,这是我的一个助手的问题。它限制了用户的数据,我修改了它并且效果很好。

    【讨论】:

      猜你喜欢
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多