【问题标题】:asp classic object to javascript object and make objects slide downasp经典对象到javascript对象并使对象向下滑动
【发布时间】:2012-08-30 19:43:45
【问题描述】:

这里有人知道如何将 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



        %>

【问题讨论】:

    标签: javascript jquery collections asp-classic slidedown


    【解决方案1】:

    您的代码中有几个错误:

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

      <%    
      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      
      
      %>
      

    【讨论】:

    • 感谢您的回复,我尝试按照您所说的进行操作,并通过此代码&lt;script type="text/javascript"&gt; for (var key in myCollection) { alert("key is " + key + " and value is " + myCollection[key]); } &lt;/script&gt; 访问了密钥,但没有任何反应
    • 您发布的代码的目的是生成一些客户端 javascript 代码,将您的服务器端集合放在一个 javascript 对象中,在您在浏览器中查看它之后查看源代码,例如 var myCollection = {Hello:你好,年龄:年龄,身高:身高,样本:样本,单词:单词};
    • 是的,我把它放在&lt;head&gt; 部分,以便我测试我的 javascript 集合被我的 vbscript 集合填充的天气。你是什​​么意思看我的来源?抱歉,我想我不明白你在说什么。
    • 我的意思是您可以通过查看您的页面源来验证您的 javascript 集合是否已填充
    • 是的,我现在看到它确实填充了我的 javascript.. 但是我为什么不能让 jquery 向它添加事件?抱歉,我对 ASP 有点陌生,我正在尽力理解它
    猜你喜欢
    • 1970-01-01
    • 2010-11-14
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 2010-11-14
    相关资源
    最近更新 更多