如何将把手参数从字符串部分转换为整数?

时间:2019-03-12 18:51:29

标签: gulp handlebars.js

我正在用Sub measurepoints() Dim i As Integer Dim j As Integer For i = 2 To 41 Cells(i, 1).Value = "=RANDBETWEEN(1,12)" Next i For j = 2 To 41 If Cells(j, 1).Value = 1 Then Cells(j, 2).Value = "=RANDBETWEEN(1,2)" ElseIf Cells(j, 1).Value = 2 Then Cells(j, 2).Value = "=RANDBETWEEN(1,2)" ElseIf Cells(j, 1).Value = 3 Then Cells(j, 2).Value = "=RANDBETWEEN(1,8)" ElseIf Cells(j, 1).Value = 4 Then Cells(j, 2).Value = "=RANDBETWEEN(1,8)" ElseIf Cells(j, 1).Value = 5 Then Cells(j, 2).Value = "=RANDBETWEEN(1,8)" ElseIf Cells(j, 1).Value = 6 Then Cells(j, 2).Value = "=RANDBETWEEN(1,8)" ElseIf Cells(j, 1).Value = 7 Then Cells(j, 2).Value = "=RANDBETWEEN(1,4)" ElseIf Cells(j, 1).Value = 8 Then Cells(j, 2).Value = "=RANDBETWEEN(1,2)" ElseIf Cells(j, 1).Value = 8 Then Cells(j, 2).Value = "=RANDBETWEEN(1,8)" ElseIf Cells(j, 1).Value = 10 Then Cells(j, 2).Value = "=RANDBETWEEN(1,10)" ElseIf Cells(j, 1).Value = 11 Then Cells(j, 2).Value = "=RANDBETWEEN(1,4)" ElseIf Cells(j, 1).Value = 12 Then Cells(j, 2).Value = "=RANDBETWEEN(1,8)" End If Next j End Sub 调用部分函数,​​因此,在该部分函数中,我需要使用{{> my-partial width="1200" }}参数才能进行类似width的算术运算(获得 600 ),但在{{divide (toInt width) 2}}帮助器中出现以下错误:

  

(节点:5185)UnhandledPromiseRejectionWarning:TypeError:期望第一个参数为数字

我也在使用gulp和assemble,在使用数学 number 车把帮手。

任何建议我该如何处理?

1 个答案:

答案 0 :(得分:0)

您可以创建自己的助手。 转到app.js(或任何应用程序入口点)并添加以下行:

var hbs = require('hbs');
hbs.registerHelper('_toInt', function(str) {
  return parseInt(str,10);
});