我正在开发一个可以向用户展示调查的应用程序.标记看起来像这样:
<body>
<div class="question" id="q1">
Question 1
</div>
<div class="question" id="q2">
Question 2
</div>
<!-- etc -->
</body>
Run Code Online (Sandbox Code Playgroud)
我想从使用jQuery的DOM构建JavaScript对象,所以在Survey
构造函数中,我穿越了jQuery使用设置each()
方法.问题是在回调函数中我无法获得Survey
对象的引用,以便将每个Question
对象附加到Survey.questions
数组.如何获得Survey
对象的引用?有没有办法将附加参数(例如Survey
对象的引用)传递给回调函数?
function Survey() {
this.questions = new Array;
$('.question').each(function(i) { (/* Survey object */).questions.push(new Question(this)); });
}
function Question(element) {
this.element = $(element);
}
Run Code Online (Sandbox Code Playgroud) 我有一个NameValueCollection
对象,我需要将它转换为一个Hashtable
对象,最好是在一行代码中.我怎样才能做到这一点?
我正在使用Raw Input API从键盘(实际上是模拟键盘的磁条卡读卡器)获取按键的集合.这里有几个代码摘录,所以你可以知道我是如何获得密钥的.
[StructLayout(LayoutKind.Sequential)]
internal struct RAWKEYBOARD
{
[MarshalAs(UnmanagedType.U2)]
public ushort MakeCode;
[MarshalAs(UnmanagedType.U2)]
public ushort Flags;
[MarshalAs(UnmanagedType.U2)]
public ushort Reserved;
[MarshalAs(UnmanagedType.U2)]
public ushort VKey;
[MarshalAs(UnmanagedType.U4)]
public uint Message;
[MarshalAs(UnmanagedType.U4)]
public uint ExtraInformation;
}
[StructLayout(LayoutKind.Explicit)]
internal struct RAWINPUT
{
[FieldOffset(0)]
public RAWINPUTHEADER header;
[FieldOffset(16)]
public RAWMOUSE mouse;
[FieldOffset(16)]
public RAWKEYBOARD keyboard;
[FieldOffset(16)]
public RAWHID hid;
}
Queue<char> MyKeys = new Queue<char>();
// buffer has the result of a GetRawInputData() call
RAWINPUT raw = (RAWINPUT)Marshal.PtrToStructure(buffer, typeof(RAWINPUT));
MyKeys.Enqueue((char)raw.keyboard.VKey);
Run Code Online (Sandbox Code Playgroud)
运行代码时,读卡器输出字符串%B40^TEST
,但在MyKeys集合中,我有以下值:
{ 16 …
Run Code Online (Sandbox Code Playgroud) 我在数据库中有一个事件日志,事件的日期时间存储为UTC时间.在我的应用程序中,我正在使用NodaTime,我将值作为a DateTime
,然后将其转换为Instant
:
var instant = NodaTime.Instant.FromDateTimeUtc(DateTime.SpecifyKind(eventDateTime, DateTimeKind.Utc));
Run Code Online (Sandbox Code Playgroud)
现在我想得到ZonedDateTime
相应的instant
使用系统的时区.我知道我可以instant.InZone(systemTimeZone)
用来满足ZonedDateTime
我的需要.但是,我不知道如何systemTimeZone
使用正确的值填充变量.如何获取与DateTimeZone
系统时区对应的对象?
在为SQL Server编写查询时,您可以声明并使用如下变量:
declare @test int
select @test = max(ID) from MyTable1
update MyTable2 set (...) where ID > @test
update MyTable3 set (...) where ID < @test
Run Code Online (Sandbox Code Playgroud)
在为MS Access编写查询时,有没有办法类似地声明和使用变量?
我需要使用另一个查询的结果填充变量,然后使用该值执行插入/更新操作.该查询将从.NET应用程序运行.