使用Prototype版本1.6.0.2.
我有一个常见的问题,当它们被抛入回调函数时会被吞下异常,通常是在我尝试处理对Ajax.Request调用的响应时.这是一个简单的例子:
HTML标记:
<input type="button" id="myButton" value="Press Me" />
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
MYSITE = {};
document.observe("dom:loaded", function () {
// Set up our helper object
MYSITE.pageHelper = new MYSITE.PageHelper();
});
MYSITE.PageHelper = function() {
console.log("PageHelper called.");
$("myButton").observe("click", this.makeCall.bindAsEventListener(this));
};
MYSITE.PageHelper.prototype.makeCall = function() {
console.log("Make call.");
new Ajax.Request(
"remoteCall.cfm",
{
method: 'get',
parameters: "",
onComplete: this.handleCallback.bindAsEventListener(this)
});
};
MYSITE.PageHelper.prototype.handleCallback = function(resp) {
console.log("Start callback processing...");
var x = missingVar + "text"; // This line generates an exception...
console.log("Finished callback processing.");
}; …Run Code Online (Sandbox Code Playgroud) 我有一个方法,我将在以下上下文中使用:
1.
用户user = null;
if(...)
{
user = defaultUser;
SetUser(a,b,user);
}
else
{
SetUser(a,b,user);
}
SaveUser(user);
Run Code Online (Sandbox Code Playgroud)
因此,某些情况下用户可能为null,而在其他情况下,它已经初始化.
我该如何设计SetUser方法?
我目前有这样的情况,但是当用户为空时,这会导致错误.
public void SetUser(object a, object b, User user)
{
if(user == null)
user = new User();
user.Security = a.security;
user.Blah = b.type;
}
Run Code Online (Sandbox Code Playgroud) 我无法找到解释这是否可行的资源.Apple文档在这里找到
......没有提到这些功能.
我还尝试使用<embed>标签嵌入音频,该标签可以拉出相同的模态快速播放器.
有没有办法做到这一点或者替代 - 有没有办法在iphone webapp中播放音频文件而无需打开模态外部播放器?
我有一个在我的计算机上运行的MFC应用程序,但是当我尝试在另一台PC上运行它时,我收到一条错误消息,表明应用程序无法初始化,我应该重新安装它.我该怎么办?
我发现自己现在经常在我的代码中使用当前模式
var dictionary = new Dictionary<type, IList<othertype>>();
// Add stuff to dictionary
var somethingElse = dictionary.ContainsKey(key) ? dictionary[key] : new List<othertype>();
// Do work with the somethingelse variable
Run Code Online (Sandbox Code Playgroud)
或者有时候
var dictionary = new Dictionary<type, IList<othertype>>();
// Add stuff to dictionary
IList<othertype> somethingElse;
if(!dictionary.TryGetValue(key, out somethingElse) {
somethingElse = new List<othertype>();
}
Run Code Online (Sandbox Code Playgroud)
这两种方式都让人觉得很迂回.我真正想要的是这样的
dictionary.GetValueOrDefault(key)
Run Code Online (Sandbox Code Playgroud)
现在,我可以为字典类编写一个扩展方法来为我做这个,但我想我可能会遗漏已经存在的东西.那么,有没有办法以更简单的方式做到这一点,而无需在字典中编写扩展方法?
我正在使用django-registration和django-profile来处理注册和配置文件.我想在注册时为用户创建个人资料.我创建了一个自定义注册表单,并使用以下教程将其添加到urls.py:
本教程中的基本思想是覆盖默认注册表单以同时创建配置文件.
forms.py - 在我的个人资料应用中
from django import forms
from registration.forms import RegistrationForm
from django.utils.translation import ugettext_lazy as _
from profiles.models import UserProfile
from registration.models import RegistrationProfile
attrs_dict = { 'class': 'required' }
class UserRegistrationForm(RegistrationForm):
city = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
def save(self, profile_callback=None):
new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email=self.cleaned_data['email'])
new_profile = UserProfile(user=new_user, city=self.cleaned_data['city'])
new_profile.save()
return new_user
Run Code Online (Sandbox Code Playgroud)
在urls.py中
from profiles.forms import UserRegistrationForm
Run Code Online (Sandbox Code Playgroud)
和
url(r'^register/$',
register,
{'backend': 'registration.backends.default.DefaultBackend', 'form_class' : UserRegistrationForm},
name='registration_register'),
Run Code Online (Sandbox Code Playgroud)
显示表单,我可以在City中输入,但不会在DB中保存或创建条目.
要测试我是否可以连接到我的数据库,我执行以下代码:
using (SqlConnection connection = new SqlConnection(myConnectionString))
{
try
{
connection.Open();
canConnect = true;
}
catch (SqlException) { }
}
Run Code Online (Sandbox Code Playgroud)
除非在连接失败时抛出异常,否则此方法有效.有没有其他方法来测试不抛出异常的Sql连接?
编辑:为了增加精度,我问是否有一个简单的方法可以做到这一点,而无需打开连接并捕获可能发生的异常
我有一个引用C++/CLI混合模式项目的WPF C#项目.我在Expression Blend 3中使用WPF项目时遇到了麻烦.我是Blend的新手,所以这很明显,但在构建项目之前它不会正确显示xaml设计器.在我的情况下,它抱怨我的自定义命令不是"识别或可访问",解决方案是在Blend中构建项目.但我无法构建项目,因为它引用了Blend无法加载的C++/CLI混合模式项目.WPF项目是纯C#,恰好引用了C++/CLI混合模式项目,但我不是要求Blend对混合模式程序集做任何事情.我该如何解决这个问题?
编辑: 通过删除对C++/CLI混合模式项目的引用并将其替换为对实际程序集的引用,我能够构建它.但是这并不理想,因为在我过去的经验中,在发布和调试配置之间切换时,Visual Studio将无法始终解析引用.
我试图在SQL Server中使用递归CTE从包含底层树结构的表中构建谓词公式.例如,我的表看起来像:
Id | Operator/Val | ParentId
--------------------------
1 | 'OR' | NULL
2 | 'AND' | 1
3 | 'AND' | 1
4 | '>' | 2
5 | 'a' | 4
6 | 'alpha' | 4
...
Run Code Online (Sandbox Code Playgroud)
...表示((a>α)AND(b>β))OR((c>γ)AND(a <delta)).
ParentId是对父节点的同一表中的Id的引用.
我想编写一个查询,它将从表中构建此字符串.可能吗?
谢谢
c# ×4
ajax ×1
arrays ×1
asp.net ×1
audio ×1
c ×1
c++-cli ×1
collections ×1
dhtml ×1
dictionary ×1
django ×1
django-forms ×1
exception ×1
html5 ×1
iphone ×1
javascript ×1
mfc ×1
profile ×1
prototypejs ×1
python ×1
registration ×1
sql-server ×1
visual-c++ ×1
wpf ×1