Meteor Autoform / SimpleSchema - quickform(type =“update”)无效

时间:2015-09-18 14:03:02

标签: meteor meteor-autoform meteor-collection2 simple-schema

我认为这是一个简单的SimpleSchema,我目前有两个模板。一个包含一个quickform,用于将新文档插入到集合中,另一个还包含一个quickform,它应该从第一个模板更新文档。

插入表单工作正常,但是当我尝试加载更新模板时,我的控制台显示以下错误,提交按钮将不起作用。根据遇到类似问题的人来说,错误通常是由递归函数引起的,但我无法在任何地方找到它。

Exception from Tracker recompute function:
debug.js:41 RangeError: Maximum call stack size exceeded
    at Object (native)
    at isObject (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1000:18)
    at isBasicObject (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1024:10)
    at parseObj (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1147:15)
    at http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1159:11
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:159:22)
    at parseObj (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1155:9)
    at http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1159:11
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:159:22)
    at parseObj (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1155:9)

以下是我的两个模板:

<template name="newWeddingPage1">
    <div class="  col-sm-10 col-sm-offset-1">
    <div class="  col-md-6">
        <div class="well well-sm">

        {{> quickForm collection="Weddings" id="insertWeddingInfo1" omitFields="email, phone, name, price" type="insert"}}

    </div>
    </div>

    <div class="  col-md-6">
        <div class="well well-sm">
        {{#each theweddingdetails}}
        <h1 id="price">{{duration}}</h1>
        {{/each}}


    </div>
    </div>



  </div>
</template>


<template name="newWeddingPage2">
    <div class="  col-sm-10 col-sm-offset-1">
    <div class="  col-md-6">
        <div class="well well-sm">
        {{#each theweddingdetails}} 
        {{> quickForm collection="Weddings" id="updateWeddingInfo1" doc="this" omitFields="email, phone, name, price" type="update"}}
        {{/each}}

    </div>
    </div>


  </div>
</template>

和我的简单架构:

Weddings.attachSchema(new SimpleSchema({

  address: {
    type: String,
    label: "Address",
    optional: true
  },
  startDate: {
    type: Date,
    label: "Date of shooting",
    optional: false,
  },
  startTime: {
    type: String,
    optional: true,
    autoform: {
      afFieldInput: {
        type: "time"
      }
    }
  },
  duration: {
    type: Number,
    label: "Duration (in hours)",
    optional: true
  },
  price: {
    type: Number,
    label: "Price",
    optional: true,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue:function(){ return 0 }
  },
  email: {
    type: String,
    optional: true,
    autoform: {
      afFieldInput: {
        type: "email"
      }
    }
  },
  phone: {
    type: Number,
    optional: true,
    autoform: {
      afFieldInput: {
        type: "tel"
      }
    }
  },
  name: {
    type: String,
    label: "Contact Person",
    optional: true
  },
  createdBy: {
    type: String,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue:function(){ return this.userId }
},
createdAt: {
    type: Date,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue:function(){ return new Date(); }
}
}));

任何人都知道我哪里出错?

现在最近几个小时一直玩弄比特:/

1 个答案:

答案 0 :(得分:2)

在您的更新表单中,您有doc="this",这意味着您只是将字符串“this”作为您的文档传递。

尝试doc=this,不带引号。这样,您将传递上下文变量this作为您的文档。我假设您在路由器或其他地方已经通过相应的文档作为您的数据上下文,以便它可以在this

中使用