小编Dve*_*Dve的帖子

在javascript中正确使用continue

我一直相信你继续使用如下:

var i;

for (i = 0;  i < 10; i++) {
  if(i%2===0) {
    continue;
  }
}   
Run Code Online (Sandbox Code Playgroud)

要么

var i, myloop;

myloop: for (i = 0;  i < 10; i++) {
  if(i%2===0) {
    continue myloop;
  }
}
Run Code Online (Sandbox Code Playgroud)

但是当我通过JSLint运行这两段代码时,我得到错误:


Problem at line 5 character 5: Unexpected 'continue'.
     continue;

我究竟做错了什么?什么是正确的用法?

javascript loops

4
推荐指数
1
解决办法
8532
查看次数

C#Reflection,使用MakeGenericMethod和具有'new()'类型约束的方法

我正在尝试使用MethodInfo MakeGenericMethod,如下所示:

        foreach (var type in types)
        {
            object output = null;
            var method = typeof (ContentTypeResolver).GetMethod("TryConstruct");
            var genmethod = method.MakeGenericMethod(type);
            var arr = new object[] { from, output };
            if ((bool)genmethod.Invoke(null, arr))
                return (IThingy)arr[1];
        }
Run Code Online (Sandbox Code Playgroud)

针对以下通用方法:

    public static bool TryConstruct<T>(string from, out IThingy result) where T : IThingy, new()
    {
        var thing = new T();
        return thingTryConstructFrom(from, out result);
    }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是我在MakeGenericMethod行上得到了一个争论异常,因为我传递的类型不是'new()'

这有什么办法?谢谢

c# generics reflection generic-method

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

如何计算响应生命周期的请求?

我正在向请求对象添加一个cookie,并从响应中的当前时间中减去它,但我假设有更好的方法来执行此操作.此外,重新使用相同的Cookie密钥可能在实际用例中不起作用.

有任何想法吗?

            RequestFilters.Add((request, response, dto) =>
                               {
                                   request.Cookies.Add("Start", new Cookie("Start", DateTime.Now.ToString()));
                                   request.ResponseContentType = ContentType.Json;
                               });

        ResponseFilters.Add((request, response, dto) =>
                                {
                                    Console.WriteLine("{0} : [{1}]", request.RawUrl, DateTime.Now.Subtract(DateTime.Parse(request.Cookies["Start"].Value)).Milliseconds);
                                    request.Cookies.Clear();
                                });
Run Code Online (Sandbox Code Playgroud)

servicestack

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

在List <Tuple>中的Item2中搜索

我一直在努力.
我怎么写这个:

/* initialization */ List<Tuple<string, string, string>> mytuple = new List<Tuple<string, string, string>>();
//pseudocode
if(mytuple.Contains("hello") in Item2)
{
    Console.Write("Success");
}
Run Code Online (Sandbox Code Playgroud)

c# tuples contains list

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

更改元素的CSS属性

我有以下jQuery,点击按钮切换手风琴菜单:

jQuery的:

$(function() {  
 $('#chooseOption').click(function(){
  $('#accordion ul').toggle();
 });    
});
Run Code Online (Sandbox Code Playgroud)

它很棒!

现在,我想知道我是否可以在切换时更改CSS heightbackground元素.所以,当我点击chooseOption它会改变heightbackground该元素的.

默认CSS:

#chooseOption {height:35px;background-image:url('1.jpg');}
Run Code Online (Sandbox Code Playgroud)

单击它将更改为:

#chooseOption {height:55px;background-image:url('2.jpg');}
Run Code Online (Sandbox Code Playgroud)

非常感谢您对此的任何指示.

css jquery onclick toggle

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

MVC3和StructureMap,基于控制器注入具体类

假设我的几个控制器构造函数采用接口 - IPetInterface IPetInterface有3个具体实现.

您将如何配置StructureMap以基于需要它的控制器提供其中一个具体实现.

原油的例子....

class DogStuff: IPetInterface{}

class CatStuff: IPetInterface{}

class GiraffeStuff: IPetInterface{}

class DogController : Controller
{
    DogController(IPetInterface petStuff)

    // some other stuff that is very unique to dogs
}

class CatController : Controller
{
    CatController(IPetInterface petStuff)

    // some other stuff that is very unquie to cats
}
Run Code Online (Sandbox Code Playgroud)

c# structuremap asp.net-mvc-3

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

通用函数错误

我正在尝试用泛型编写简单的C#函数.例如,数组解析器.

public static int parse_array <T> ( string str, ref T[] array ) 
    where T : IConvertible<T>
{
    string[] vals=str.Split(new char[]{'','\t',',',';'}, StringSplitOptions.RemoveEmptyEntries);

    if( vals==null || vals.Length==0 )
        return 0;

    array = new T[vals.Length];

    for( int i=0; i<vals.Length; i++ )
    {
        array[i] = Convert.ChangeType ( vals[i], T );
    }

    return vals.Length; 
}
Run Code Online (Sandbox Code Playgroud)

但我收到错误:非泛型类型'System.IConvertable'不能与type参数一起使用.怎么了 ?

c# generics

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

如何进行多个正则表达式替换

我有我的域名字符串:

www.my.domain.com
Run Code Online (Sandbox Code Playgroud)

我希望我的输出是:

my.domain
Run Code Online (Sandbox Code Playgroud)

我现在这样做:

str.replace("www.","").replace(".com","")
Run Code Online (Sandbox Code Playgroud)

如何只用一个替换而不是两个?

javascript regex string

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

extjs嵌套模型

我是Sencha Extjs的新手,我遇到了模型设计问题.以下是来自服务器的示例响应:

[
{
    "success": "true",
    "data": {
        "sromain": [
            {
                "corporation": "DEV 1 s.r.o.",
                "dbName": "dev_1_s_r_o_",
                "prijmyCelk": "2 106,00 €",
                "nakladyCelk": "2 049,00 €",
                "ziskCelk": "57,00 €",
                "neuhrVydCelk": "2 106,00 €",
                "neuhrPrijCelk": "2 049,00 €",
                "dph": "9,52 €"
            }
        ],
        "branches": [
            {
                "branch_name": "Bratislava",
                "branch_code": "BA",
                "strediskoprijmyCelk": "180,00 €",
                "strediskonakladyCelk": "0,00 €",
                "strediskoziskCelk": "180,00 €",
                "strediskoneuhrVydCelk": "180,00 €",
                "strediskoneuhrPrijCelk": "0,00 €",
                "streddphCelk": "30,00 €"
            },
            {
                "branch_name": "Banská Bystrica",
                "branch_code": "BB",
                "strediskoprijmyCelk": "600,00 €",
                "strediskonakladyCelk": "0,00 €",
                "strediskoziskCelk": …
Run Code Online (Sandbox Code Playgroud)

json nested model extjs

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

我如何在多个表中搜索?

我如何在多个表中搜索?我有这个代码,但这只适用于我的一个表.我总共有4张桌子.

这是我的表格中"某事"之后的搜索代码.

$(document).ready(function() {
    $('#search').keyup(function() {
        searchTable($(this).val());
    });
});

function searchTable(inputVal) {
    var table = $('#searchTable');
    table.find('tr').each(function(index, row) {
        var allCells = $(row).find('td');
        if(allCells.length > 0) {
            var found = false;
            allCells.each(function(index, td) {
                var regExp = new RegExp(inputVal, 'i');
                if(regExp.test($(td).text())) {
                    found = true;
                    return false;
                }
            });
            if(found == true) $(row).show();
            else $(row).hide();
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

我已经剥离了我的表格代码,以便它看起来更易于管理

问题在于"搜索tabe"只运行表1而不是剩余的表

表格1:

<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)

表2:

<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)

表3:

<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)

表4:

<table class="table" id="searchTable">
Run Code Online (Sandbox Code Playgroud)

html javascript

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

无法为元素设置值

我试图在javascript中为元素(id ctl30_txtTextBox)设置一个值.

$.ajax({
     type: "POST",
     contentType: "application/json; charset=utf-8",
     url: "IndexMask.aspx/AttachBarcodeFile",
     dataType: "json",
     data: params,
     success: function() {
         $("#<%= DummyPostbackButton.ClientID %>").click();
         var someOtherName = "abc";
         var element = document.getElementById("ctl30_txtTextBox");
         element.Value = someOtherName;
         alert(element.value.toString());
     },
     error: function(request, status, error) {
         alert("Error attaching barcode file.");
     }
 });
Run Code Online (Sandbox Code Playgroud)

我得到了元素,但价值从未设定.如果我在页面上设置了值,则会显示具有正确值的警报.

我究竟做错了什么?

javascript

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