【问题标题】:METEOR - Automatically increment order numbersMETEOR - 自动增加订单号
【发布时间】:2015-10-13 01:41:25
【问题描述】:

我需要做的是使用 collection-2 或另一个包来自动创建一个新的订单号,从上次使用的订单号递增。

即从PO123456开始,当我保存这个订单时,下次我做新的PO时,它会自动生成编号PO123457。

我一直在寻找一个好的示例或教程,但找不到。

【问题讨论】:

  • 有人建议我查看 konecty:mongo-counter 包,但我仍然很难掌握它。有什么教程可以帮助我学习如何合并语法?

标签: meteor meteor-collection2


【解决方案1】:

konecty:mongo-counteraldeed:collection2aldeed:simple-schema 结合使用应该非常简单。在您的架构定义中尝试:

POnumber: { type: String, autoValue: function(){
  if ( this.isInsert ){ // restrict to when inserting a document
    var currentNumber = incrementCounter('purchase order'); // this will use mongo-counter

    // WARNING: you can only ever get as rich as 10M POs!!
    var zeroPad = "000000" + currentNumber; // pad with 6 zeros

    zeroPad = zeroPad.substr(zeroPad.length-7); // restrict to 7 places 
    return 'PO' + zeroPad; // prefix with 'PO' 

  } else if ( this.isSet ){
    this.unset(); // prevent attempts to change the number
  }
}

【讨论】:

    猜你喜欢
    • 2013-05-12
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 2010-09-05
    • 2017-11-06
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    相关资源
    最近更新 更多