public class a
{
public event eventhandler test;
public void RaiseTest(){//fire test}
}
Run Code Online (Sandbox Code Playgroud)
是否可以在不调用方法的情况下,从此类外部进行此类测试?
基本上,我有大量事件必须基于外部源引发,并且不想为每个事件创建Raise()函数。
是否可以创建一个通用的Raise()来接受要引发的事件作为参数?因此仍然可以在班级内部调用它吗?
如何将args传递给事件处理函数?这将在页面加载上运行该功能,这不是所需的效果.我需要这个例程"validateText"来运行几个不同的文本框,下拉组合.我可以重用"validateText"而不是每个文本/下拉组合创建一个??
//add blur event handler to the textbox with jQuery when the page is finished loading
$(document).ready(function() {
$("#myTextbox").blur(validateText($("#myTextbox"), $("#Select1")));
})
function validateText(textbox, dropdown) {
var message = $("#message");
var isValid = false;
//get the value the user type in
var textboxValue = $(textbox).val();
//get the options from the lookup
var options = $("option", dropdown);
//loop through the options and compare it to "value"
options.each(function() {
var optValue = $(this).val();
if (optValue === textboxValue) {
isValid = true;
}
}); …Run Code Online (Sandbox Code Playgroud) 给定一个数组[1, 2, 3, 4],我如何找到其元素的总和?(在这种情况下,总和将是10.)
我认为$.each可能有用,但我不确定如何实现它.
请记下这个使用 Microsoft Visual Studio 2008 编写的小型 WPF C# 程序的代码:
.xaml
<Window x:Class="WpfDatagridTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="Window1" Height="300" Width="300">
<Grid>
<WpfToolkit:DataGrid
x:Name="DataGrid_" ItemsSource="{Binding}"
SelectionMode="Extended"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="False" CanUserSortColumns="False"
AutoGenerateColumns="False"
RowHeaderWidth="17" RowHeight="25" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
。CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls;
namespace WpfDatagridTest
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window …Run Code Online (Sandbox Code Playgroud) 是否可以配置Emacs,以便在emacs窗口失去焦点时保存所有文件?
我有几个类需要加载一些属性文件,我想知道实现这一目标的最佳实践是什么.我想到了两种基本方法:
对每个类中的属性文件名进行硬编码,然后使用Properties该类从a加载FileInputStream,如果有人决定更改属性文件的名称,则可能会出现问题,因为它在代码中是硬编码的.
Run Code Online (Sandbox Code Playgroud)public class A { public A() { Properties p = new Properties().load( new FileInputStream("properties/Aconfig.properties")); String value = p.getProperty("key", ""); } }
创建一个方法,给定一个类名,加载一个与该类同名的属性文件.虽然这种方法不需要对属性文件名进行硬编码,但它确实要求我们在命名文件时遵循一些约定,这可能会引起混淆.
Run Code Online (Sandbox Code Playgroud)public class A { public A() { Properties p = PropertiesHelper.loadFromClassName(A.class.getName()); // here, we **assume** that there is a A.properties file in the classpath. } }
但是,可能还有许多其他更优雅的方法,这就是我提出这些问题的原因:i)在Java中加载属性文件的最佳实践是什么?ii)你是否使用任何照顾工作的帮助班?iii)在哪里(在代码中)你通常加载属性文件?
另外,类可以"自动加载"其属性吗?或者我应该将我需要的参数传递给构造函数?传递参数的问题在于,某些类(~20,表示统计模型中的参数)的方法太多了.
我无法通过Maven依赖获取最新版本的Hibernate.看来我可以从Maven中央存储库获取的最新版本是3.2.6.GA,我对使用3.3.2.GA很感兴趣,这是hibernate.org网站上显示的最新版本.当我在项目的pom.xml中将我的hibernate依赖项修改为最新版本时,运行Maven构建时出现以下错误:
Missing:
----------
1) org.hibernate:hibernate:jar:3.3.2.GA
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate -D
version=3.3.2.GA -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.hibernate -DartifactId=hibernate -Dve
rsion=3.3.2.GA -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[
id]
Run Code Online (Sandbox Code Playgroud)
一旦我这样做,我继续得到错误,表明我需要添加一个javassist依赖,然后我需要更新我的hibernate-validator依赖,这也需要在本地安装,然后我停下来,环顾四周,看看是否有一种更好的方法,可能将Maven指向JBoss/Hibernate存储库等等.与我使用的其他重要的开放源代码包(例如Spring或JUnit)相比,这真的很令人头疼 - 当我发布了新版本时do是更新依赖元素中的版本号,它只是工作.
我已经尝试将以下存储库声明添加到我的pom.xml中,但没有任何乐趣:
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
我搜索谷歌并没有找到太多帮助.有人可以提出最直接的方式来使用最新版本的hibernate或hibernate-core(3.3.2.GA),hibernate-validator(3.1.0)和hibernate-annotations(3.4.0)?
如何清空Drupal缓存:
实际上,您如何指示最终用户清除其缓存?
在Ruby 1.8.6中,我有一个数组,比如100,000个用户id,每个用户id都是一个int.我想在这些用户ID上执行一段代码,但我想以块的形式执行.例如,我想一次处理100个.我怎样才能尽可能简单地实现这一目标?
我可以做类似下面的事情,但可能有一个更简单的方法:
a = Array.new
userids.each { |userid|
a << userid
if a.length == 100
# Process chunk
a = Array.new
end
}
unless a.empty?
# Process chunk
end
Run Code Online (Sandbox Code Playgroud) 我有一个CustomValidator,用于验证几种不同电话号码方案的电话号码.客户端javascript看起来像这样:
validatePhoneNumber(sender, args) {
cleanNumber = args.Value.replace(/\D/, "");
country = $("#" + CountryID).get(0).value;
switch (country) {
case "North America":
args.IsValid = validateNAPhoneNumber(cleanNumber);
if (!args.IsValid) sender.errormessage = "* Not a NA Phone #";
break;
case "UK":
args.IsValid = validateUKPhoneNumber(cleanumber);
if (!args.IsValid) sender.errormessage = "* Not a UK Phone #";
break;
...
}
}
Run Code Online (Sandbox Code Playgroud)
实际验证正确进行,CustomValidator始终具有正确的IsValid属性.然而,sender.errormessage似乎在此函数调用它的默认值之后被重写.如何更改errormessage值,并使其"坚持"?
javascript ×3
arrays ×2
c# ×2
jquery ×2
asp.net ×1
autosave ×1
caching ×1
cell ×1
client-side ×1
datagrid ×1
dependencies ×1
drupal ×1
drupal-cache ×1
ecma262 ×1
elisp ×1
emacs ×1
events ×1
focus ×1
hibernate ×1
java ×1
maven-2 ×1
pom.xml ×1
properties ×1
raise ×1
ruby ×1
validation ×1
wpf ×1
wpftoolkit ×1