0

这里有人知道如何将 ASP 集合存储到 Javascript 集合吗?我从以前的帖子中得到了一个代码,但没有投入使用,我一定是把代码放在了错误的地方。

我目前正在开发一个应用程序,其中一旦文档准备好,来自 ASP 集合的每个变量都会一次向下移动一个。我决定使用 jquery 向下滑动每个值,因为它有一个 slideDown 事件。但是当我从集合中滑下项目时,同时滑下所有项目。这里的任何人都知道如何做到这一点或提出更好的方法来做到这一点?

<%

        Dim objDictionary, Key,searchWord, myVar,a,i, break
        searchWord = request.QueryString("searchWord")



        Set objDictionary = CreateObject("Scripting.Dictionary")
        objDictionary.CompareMode=1
        objDictionary.Add "Hello","hello"
        objDictionary.Add "Age","age"
        objDictionary.Add "height","height"
        objDictionary.Add "sample","sample"
        objDictionary.Add "words","words"


        Response.Write "<div id='toFall'>"
        if objDictionary.Exists(searchWord) then
            objDictionary.Remove(searchWord)
           a = objDictionary.Keys


            for i=0 to objDictionary.Count-1
            Response.Write( "<div class='fall'>" + a(i)) 
            Response.write("<br />")
            Response.write("</div>")

            next
            set objDictionary=nothing
        else 
            a = objDictionary.Keys

            for i=0 to objDictionary.Count-1
            Response.Write( "<div class='fall'>" + a(i)) 
            Response.write("<br />")
            Response.write("</div>")
            next
            set objDictionary=nothing

        end if      

        Response.write "</div>" 

'got this code from my previous post but didn't got it working  
        Sub CollectionToJavaScript(oCollection, sClientSideName) 
            Dim blnFirst
            blnFirst = True
            Response.Write("<" & "script" & " type=""text/javascript"">")
            Response.Write("var " & sClientSideName & " = {")
            For Each key In objDictionary.Keys
                If Not(blnFirst) Then Response.Write(", ")
                Response.Write( key & ": " & objDictionary(key) )
                blnFirst = false
            Next
            Response.Write("};")
            Response.Write("</" & "script>")
            Call CollectionToJavaScript (objDictionary, "myCollection")
        End Sub



        %>
4

1 回答 1

0

您的代码中有几个错误:

  1. 在调用 CollectionToJavaScript 子之前,您将字典对象设置为空
  2. 您需要在 CollectionToJavaScript 子中使用 oCollection
  3. Response.Write(key & ": " & objDictionary(key) )
    blnFirst = false的定位

    <%    
    Dim objDictionary, Key,searchWord, myVar,a,i, break         
    searchWord = request.QueryString("searchWord")            
    
    Set objDictionary = CreateObject("Scripting.Dictionary")         
    objDictionary.CompareMode=1         
    objDictionary.Add "Hello","hello"         
    objDictionary.Add "Age","age"         
    objDictionary.Add "height","height"         
    objDictionary.Add "sample","sample"         
    objDictionary.Add "words","words"           
    
    Response.Write "<div id='toFall'>"         
    
    if objDictionary.Exists(searchWord) then     
    
        objDictionary.Remove(searchWord)            
        a = objDictionary.Keys               
        for i=0 to objDictionary.Count-1             
            Response.Write( "<div class='fall'>" + a(i))              
            Response.write("<br />")             
            Response.write("</div>")              
        next                    
    
    else   
    
        a = objDictionary.Keys              
        for i=0 to objDictionary.Count-1             
            Response.Write( "<div class='fall'>" + a(i))              
            Response.write("<br />")             
            Response.write("</div>")             
        next                   
    
    end if                
    
    Response.write "</div>"   'got this code from my previous post but didn't got it working           
    
    Sub CollectionToJavaScript(ByRef oCollection, sClientSideName)              
    Dim blnFirst             
    blnFirst = True             
    
        Response.Write("<" & "script" & " type=""text/javascript"">")             
        Response.Write("var " & sClientSideName & " = {")             
    
        For Each key In oCollection.Keys                 
        If Not(blnFirst) Then 
            Response.Write(", ")                       
        End If    
        Response.Write( key & ": " & oCollection(key) )     
        blnFirst = false       
        Next   
    
    Response.Write("};")             
    Response.Write("</" & "script>")             
    End Sub          
    
    Call CollectionToJavaScript (objDictionary, "myCollection")    
    
    set objDictionary=nothing      
    
    %>
    
于 2012-08-31T08:28:09.913 回答