问题列表 - 第24639页

原型回调函数吞噬异常

使用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)

javascript ajax dhtml prototypejs

5
推荐指数
1
解决办法
1620
查看次数

帮助设计一个方法,我应该使用out还是ref或返回类型?

我有一个方法,我将在以下上下文中使用:

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)

c# asp.net

0
推荐指数
1
解决办法
89
查看次数

在mobilesafari webapp中嵌入html5 <audio>.是否可以在模态播放器中加载图像代替quicktime徽标?

我无法找到解释这是否可行的资源.Apple文档在这里找到

https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html#//apple_ref/doc/uid/TP40009523-CH2-SW1

......没有提到这些功能.

我还尝试使用<embed>标签嵌入音频,该标签可以拉出相同的模态快速播放器.

有没有办法做到这一点或者替代 - 有没有办法在iphone webapp中播放音频文件而无需打开模态外部播放器?

iphone audio html5

6
推荐指数
1
解决办法
1万
查看次数

[VC++]如何在另一台PC上运行我的程序?

我有一个在我的计算机上运行的MFC应用程序,但是当我尝试在另一台PC上运行它时,我收到一条错误消息,表明应用程序无法初始化,我应该重新安装它.我该怎么办?

mfc visual-c++

3
推荐指数
1
解决办法
1473
查看次数

如果键不存在,则字典返回默认值

我发现自己现在经常在我的代码中使用当前模式

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)

现在,我可以为字典类编写一个扩展方法来为我做这个,但我想我可能会遗漏已经存在的东西.那么,有没有办法以更简单的方式做到这一点,而无需在字典中编写扩展方法?

c# collections dictionary

216
推荐指数
4
解决办法
14万
查看次数

Django-Registration和Django-Profile,使用您自己的自定义表单

我正在使用django-registration和django-profile来处理注册和配置文件.我想在注册时为用户创建个人资料.我创建了一个自定义注册表单,并使用以下教程将其添加到urls.py:

http://dewful.com/?p=70

本教程中的基本思想是覆盖默认注册表单以同时创建配置文件.

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中保存或创建条目.

python django profile registration django-forms

31
推荐指数
2
解决办法
4万
查看次数

测试sql连接而不抛出异常

要测试我是否可以连接到我的数据库,我执行以下代码:

using (SqlConnection connection = new SqlConnection(myConnectionString))
{
   try
   {
      connection.Open();
      canConnect = true;
   }
   catch (SqlException) { }
}
Run Code Online (Sandbox Code Playgroud)

除非在连接失败时抛出异常,否则此方法有效.有没有其他方法来测试不抛出异常的Sql连接?

编辑:为了增加精度,我问是否有一个简单的方法可以做到这一点,而无需打开连接并捕获可能发生的异常

c# sqlconnection exception

8
推荐指数
1
解决办法
3万
查看次数

处理Expression Blend缺乏对C++/CLI项目的支持

我有一个引用C++/CLI混合模式项目的WPF C#项目.我在Expression Blend 3中使用WPF项目时遇到了麻烦.我是Blend的新手,所以这很明显,但在构建项目之前它不会正确显示xaml设计器.在我的情况下,它抱怨我的自定义命令不是"识别或可访问",解决方案是在Blend中构建项目.但我无法构建项目,因为它引用了Blend无法加载的C++/CLI混合模式项目.WPF项目是纯C#,恰好引用了C++/CLI混合模式项目,但我不是要求Blend对混合模式程序集做任何事情.我该如何解决这个问题?

编辑: 通过删除对C++/CLI混合模式项目的引用并将其替换为对实际程序集的引用,我能够构建它.但是这并不理想,因为在我过去的经验中,在发布和调试配置之间切换时,Visual Studio将无法始终解析引用.

c# wpf c++-cli expression-blend

7
推荐指数
1
解决办法
592
查看次数

如何获得char**的长度?

快问问题:如何知道char*foo []的长度?

谢谢.

c arrays

5
推荐指数
2
解决办法
1万
查看次数

递归CTE问题

我试图在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的引用.

我想编写一个查询,它将从表中构建此字符串.可能吗?

谢谢

sql-server recursive-cte

6
推荐指数
2
解决办法
1692
查看次数