传递数据时节点connect-flash显示消息

时间:2016-11-20 07:28:36

标签: node.js

我刚开始尝试使用connect-flash并且有一个奇怪的效果,如果我这样做,我的代码可以工作:

Sub TestWrite()
    Const FULLNAME As String = "C:\Users\sang\Desktop\Book2.xlsm"

    Dim objExcel As Object, WB As Object, WS As Object
    Set objExcel = getExcelAppication
    objExcel.Visible = True
    Set WB = getWorkbook(objExcel, FULLNAME)

    If WB Is Nothing Then
        MsgBox "File not found: " & FULLNAME, vbInformation, ":("
    Else
        Set WS = WB.Worksheets("Sheet1")
        WS.Range("A1").Value = "haha"
    End If

End Sub

Function getExcelAppication() As Object
    Dim objExcel As Object
    If GetObject("winmgmts:").ExecQuery("select * from win32_process where name='Excel.exe'").Count > 0 Then
        Set objExcel = GetObject(, "Excel.Application")
    Else
        Set objExcel = CreateObject("Excel.Application")
    End If
    Set getExcelAppication = objExcel
End Function

Function getWorkbook(objExcel As Object, FULLNAME As String) As Object
    Dim ShortName As String
    Dim WB As Object, WS As Object
    ShortName = Right(FULLNAME, Len(FULLNAME) - InStrRev(FULLNAME, "\"))

    For Each WB In objExcel.Workbooks
        If WB.Name = ShortName Then
            Set getWorkbook = WB
            Exit Function
        End If
    Next

    Set getWorkbook = objExcel.Workbooks.Open(FULLNAME)

End Function

但如果我这样做,它就不会(它在我的模板中显示一个数字,每次加载时都会增加:

router.get('/signup', function(req, res) {
  req.flash('test', 'message goes here');  
  res.render('signup.ejs', { message: req.flash('test') });
});

任何人都知道发生了什么/如何将消息设置在一行而不是两行?

1 个答案:

答案 0 :(得分:0)

在第一个示例中,您已经为键“test”分配了一个值,因此在模板上呈现消息时,它将检索“消息在此处

对于第二部分,假设您使用的是玉模板,则必须循环:

for message in flash
     p= message.message