【问题标题】:How to convert property name to lowercase from object using angularjs?如何使用angularjs将属性名称从对象转换为小写?
【发布时间】:2015-11-28 19:26:30
【问题描述】:

这是我的代码

$scope.search={"className":{"Id":"101","Class":"business"}};

以上数据来自另一个控件,现在我正在访问像 $scope.search.className.Class; 这样的 Class 属性,但我只想在 angularjs 中将属性 Class 转换为像 $scope.search.className.class; 这样的小写。

【问题讨论】:

标签: angularjs


【解决方案1】:

您可以通过遍历整个对象并编写一个函数将所有属性转换为小写来实现它:

for(var prop in obj){
    //Make a new property name with lowercase
    obj[prop.toLowerCase()]=a[s];
    //delete the original property with uppercase name
    delete a[s];
}

请记住,如果您的对象中有属性名称,只是大小写不同,这将无法正常运行,例如:{foo:"bar",Foo:"baz"}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 2015-12-30
    • 2014-12-21
    相关资源
    最近更新 更多