我正在尝试在Session变量中存储一个表项列表,以跟踪项目复选框的最后一个状态(CHECKED或UNCHECKED)。
我首先在用户第一次加载页面时将所有值设置为UNCHECKED。这部分代码似乎有效:
model = Request.querystring("model")
If IsEmpty(Session(model)) Then
Set dicX = CreateObject("Scripting.Dictionary")
sqlStr = "SELECT DISTINCT level FROM IFPDB WHERE IFPDB.model='"
sqlStr = sqlStr & model
sqlStr = sqlStr & "'"
Set objRS = objConn.Execute(sqlStr)
' For each unique level get all of that levels menu names
Do While (Not objRS.EOF)
level = objRS("level")
dicX.Add level, CreateObject("Scripting.Dictionary")
' for each menu name set the initial state to OFF
sqlStr2 = "SELECT * FROM IFPDB WHERE IFPDB.model='"
sqlStr2 = sqlStr2 & model
sqlStr2 = sqlStr2 & "' AND IFPDB.level='"
sqlStr2 = sqlStr2 & level_name
sqlStr2 = sqlStr2 & "'"
Set objRS2 = objConn.Execute(sqlStr2)
Do While (Not objRS2.EOF)
menu_item = objRS2("menu_names")
dicX(level).Add menu_item, CreateObject("Scripting.Dictionary")
' add a dictionary item
dicX(level)(menu_item).Add "menu_state", "UNCHECKED"
objRS2.MoveNext
Loop
objRS.MoveNext
Loop
Set Session(model) = dicX
End If
当我尝试读取任何这些值时,问题就出现了。无论我如何尝试访问它们,我都会得到“Object_required:_'[undefined]”“
我试过
' Check the last state of this option
menu_name = objResult("menu_names")
response.write(menu_name & "<br>") ' writes correctly
If Not IsEmpty(Session(model))
my_state = Session(model)(current_level)(menu_name).Item("menu_state") ' dies here
response.write(my_state & "<br>")
End If
' tried these as well
my_state = Session(model)(current_level)(menu_name)("menu_state")
'and
my_state = Session(model)(current_level).Item(menu_name).Item("menu_state")
'and others
我想我只是不知道如何阅读我制作的Session变量。有什么想法吗?
答案 0 :(得分:1)
请参阅: Can I store a Scripting Dictionary in a session variable?
您必须从会话中提取字典并输入新变量。
dim state
set state = Session(model)
您还缺少'item'部分:
my_state = state.item(current_level).item(menu_name).item("menu_state")
答案 1 :(得分:0)
使用Session(“model”)代替Session(模型)。