Meteor 如何使用Autoform以时间格式显示数字?

Meteor 如何使用Autoform以时间格式显示数字?,meteor,time,meteor-autoform,Meteor,Time,Meteor Autoform,我目前正在使用Autoform在Meteor中制作一个表单,并试图让用户输入他们想要用于事件的时间限制。我当前的模式与下面的示例类似,但我只是想知道如何更改timeLimit对象,以便它不只是以“0”格式显示数字,而是以“00:00”格式返回,并使我能够在几秒钟内记录信息 EventSchema = new SimpleSchema({ name: { type: String, label: "Event Name" }, timeLimit: { type

我目前正在使用Autoform在Meteor中制作一个表单,并试图让用户输入他们想要用于事件的时间限制。我当前的模式与下面的示例类似,但我只是想知道如何更改timeLimit对象,以便它不只是以“0”格式显示数字,而是以“00:00”格式返回,并使我能够在几秒钟内记录信息

EventSchema = new SimpleSchema({
  name: {
    type: String,
    label: "Event Name"
  },
  timeLimit: {
    type: Number,
    label: "Time Limit"
  },
  rounds: {
    type: Number,
    label: "Rounds"
  }
});

一种方法是为用户输入一个字段,该字段将是“mm:ss”格式的字符串。以及另一个计算并显示秒数的字段

因此,在本例中,您将在表单上显示timeLimitString字段,以便用户可以以“mm:ss”格式输入。并使用timeLimit字段上的autoValue函数计算秒数(本例使用矩.js库计算秒数)


是否需要一个文本字段,以便他们能够键入秒数?他们是否也需要能够以“00:00”格式键入?或者你想让他们打一个,然后把它转换成另一个?@AutumnLeonard对不起,我想我不够具体。他们需要能够输入格式“00:00”或按下侧面的加号/减号按钮,使分钟数上升/下降。
EventSchema = new SimpleSchema({
  name: {
    type: String,
    label: "Event Name"
  },
  timeLimitString: {
    type: String,
    regEx: // define regex here for "mm:ss" format
  },
  timeLimit: {
    type: Number,
    label: "Time Limit",
    autoValue: function() {
       var string = this.field("timeLimitString");
       if (string.isSet) {
           var time = moment(string.value, "mm:ss");
           var seconds = time.minutes()*60 + time.seconds();
           return seconds;
        }
    }
  },
  rounds: {
    type: Number,
    label: "Rounds"
  }
});