小编col*_*nde的帖子

如何从JavaScript对象获取项目?

如何从JavaScript对象获取项目:

var items = [
  {
    ITEM:1,
    AMOUNT:10
  },
  {
    ITEM:2,
    AMOUNT:20
  }
];
Run Code Online (Sandbox Code Playgroud)

我希望能够做到这样的事情:

$(items).filter(ITEM == 1).AMOUNT;
Run Code Online (Sandbox Code Playgroud)

......会回来的10.

javascript jquery json

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

Javascript 匹配字符串内的括号

如何对字符串中有括号的字符串进行 .match 匹配?String1.match("我如何匹配这个 (MATCH ME)");


没有一个答案能让我得到我想要的。我可能只是做错了。我试图让我的问题变得基本,我认为这样做问我的问题是错误的。这是我要修复的声明:

$('[id$=txtEntry3]').focus(function () {

    if (!DropdownList.toString().match($('[id$=txtEntry2]').val()) || $('[id$=txtEntry2]').val().length < 5) {
        $('[id$=txtEntry2]').select();

        ErrorMessageIn("The Ingredient number you entered is not valid.");
        return;
    }
    ErrorMessageOut();
});
Run Code Online (Sandbox Code Playgroud)

这可以正常工作,我遇到的问题是当它尝试匹配来自“txtEntry2”且其中包含“()”的条目时。



嗯,它有点坏了,但它适用于我需要它做的事情。这是我为解决问题所做的工作:

$('[id$=txtEntry3]').focus(function () {

        if (!StripParentheses(DropdownList).match(StripParentheses($('[id$=txtEntry2]').val())) || $('[id$=txtEntry2]').val().length < 5) {
            $('[id$=txtEntry2]').select();
            if (!$('[id$=txtEntry2]').val() == "") {
                ErrorMessageIn("The Ingredient number you entered is not valid.");
            }
            return;
        }
        ErrorMessageOut();
    });

function StripParentheses(String){
    x = String.toString().replace(/\(/g, '');
    x = x.toString().replace(/\)/g, '');
    return x;
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

Automapper将小数设置为2位小数

我想使用AutoMapper链接我的两个对象.它运行良好,但现在我想将我的小数项格式化为全数字2到2位小数.

这就是我所拥有的.我究竟做错了什么?

Mapper.CreateMap<Object1, Object2>()
.ForMember(x => typeof(decimal), x => x.AddFormatter<RoundDecimalTwo>());
Run Code Online (Sandbox Code Playgroud)

这是RoundDecimalTwo格式化程序

public class RoundDecimalTwo : IValueFormatter
    {
        public string FormatValue(ResolutionContext context)
        {
            return Math.Round((decimal)context.SourceValue,2).ToString();
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# mapping automapper

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

标签 统计

javascript ×2

jquery ×2

automapper ×1

c# ×1

json ×1

mapping ×1