简体   繁体   English

在JQuery中访问ASP经典Collection变量

[英]Accessing ASP classic Collection variable in JQuery

Hi guys im just new with asp classic and jquery and am just wondering if there is a way wherein i can pass my collection variables to jquery. 嗨,大家好,我是ASP Classic和jquery的新手,我只是想知道是否有一种方法可以将我的集合变量传递给jquery。 my goal is to make the variables slide down one at a time. 我的目标是使变量一次向下滑动。 I came across the .slideDown function on jquery so i tried using it but doesn't seem to work so i guess what's wrong is my mark up... any help will be greatly appreciated. 我在jquery上遇到了.slideDown函数,因此我尝试使用它,但似乎无法正常工作,所以我想我的问题是什么...任何帮助将不胜感激。

ASP CODE: ASP代码:

        <%

        Dim objDictionary, Key,searchWord, myVar,a,i, break
        searchWord = request.QueryString("searchWord")
        break = Response.write("<br />")


        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"



        if objDictionary.Exists(searchWord) then
            objDictionary.Remove(searchWord)
           a = objDictionary.Keys

            for i=0 to objDictionary.Count-1
            Response.Write(a(i)) 
            break

            next
            set objDictionary=nothing
        else 
            a = objDictionary.Keys

            for i=0 to objDictionary.Count-1
            Response.Write(a(i)) 
            break
            next
            set objDictionary=nothing

        end if      


        %>

JQUERY CODE: JQUERY代码:

<script type="text/javascript">
    $(document).ready(function(){
    $("#toFall").slideDown("slow");});
</script>

Have you tried placing each dictionary key in some kind of DOM container, like a div - each of which are children of #toFall, eg: 您是否尝试过将每个字典键放在某种DOM容器中,例如div-每个字典键都是#toFall的子代,例如:

   Response.write "<div id='#toFall'>"  
   for i=0 to objDictionary.Count-1
        Response.Write "<div>" + (a(i)) + "</div>"
   next 
   Response.write "</div>"

^^Please double check the syntax - my VBScript is rusty. ^^请仔细检查语法-我的VBScript生锈了。 Also - are you sure you want that break in the loop - doesn't that mean only one write occurs? 另外-您确定要在循环中中断-难道这意味着只发生一次写操作?

Here is a generic method that will send any classic ASP collection (with Keys and values) to be a JavaScript collection: 这是一种通用方法,该方法会将任何经典的ASP集合(带有键和值)发送为JavaScript集合:

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>")
End Sub

First parameter is the collection, second is the desired name of the client side variable to hold the JavaScript collection. 第一个参数是集合,第二个参数是用于保存JavaScript集合的客户端变量的所需名称。

This will create client side complex object that can be later accessed using the name you provided as the second parameter of the above method. 这将创建客户端复杂对象,以后可以使用您提供的名称作为上述方法的第二个参数来对其进行访问。

General way to debug that it's working: 调试其正常工作的一般方法:

<script type="text/javascript">
for (var key in myCollection) {
    alert("key is " + key + " and value is " + myCollection[key]); 
}
</script>

In your case, you should call this method like that after populating the collection: 对于您的情况,应在填充集合后像这样调用此方法:

Call CollectionToJavaScript (objDictionary, "myCollection")

Then in your jQuery, assuming you want to slide down all the keys (ie all keys are valid DOM elements) have such code: 然后在您的jQuery中,假设您要向下滑动所有键(即所有键都是有效的DOM元素),则应具有以下代码:

$(document).ready(function() {
    for (var key in myCollection) {
        $("#" + key).slideDown("slow");
    }
});

If you also need the value associated with each key, access it by using myCollection[key] in the loop. 如果还需要与每个键关联的值,请在循环中使用myCollection[key]进行访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM