AngularJS ng-repeat仅显示指定键值

时间:2021-05-13 07:41:47

My data structure is:

我的数据结构是:

{"code":"AAA","name":"AAA industries","date":null}

I am trying to display just the name in a button. I am trying to use the following:

我试图在按钮中显示名称。我想使用以下内容:

<div ng-repeat="item in company.details">
    <button ng-repeat="(key, val) in item">
        {{val}}
    </button>
</div>

but of course that displays everything. What's my next step here?

但当然这显示了一切。我的下一步是什么?

3 个解决方案

#1


2  

use this

check for key, if it is equal to name then display else dont

检查密钥,如果它等于name,则显示else else

 <div ng-repeat="item in company.details">
        <button ng-repeat="(key, val) in item">
            <span ng-if="key=='name'">{{val}}</span>
        </button>
    </div>

#2


0  

Here is a jsBin illustrating an answer.

这是一个说明答案的jsBin。

The code logic is as follows:

代码逻辑如下:

<body ng-app="MyApp" ng-controller="myController">
  <div ng-repeat="item in data">
    {{item.name}}
  </div>
</body>

#3


0  

Kolban is correct. So in your case the answer would be:

Kolban是对的。所以在你的情况下答案是:

<div ng-repeat="item in company.details"> {{item.val}} </div>

{{item.val}}

#1


2  

use this

check for key, if it is equal to name then display else dont

检查密钥,如果它等于name,则显示else else

 <div ng-repeat="item in company.details">
        <button ng-repeat="(key, val) in item">
            <span ng-if="key=='name'">{{val}}</span>
        </button>
    </div>

#2


0  

Here is a jsBin illustrating an answer.

这是一个说明答案的jsBin。

The code logic is as follows:

代码逻辑如下:

<body ng-app="MyApp" ng-controller="myController">
  <div ng-repeat="item in data">
    {{item.name}}
  </div>
</body>

#3


0  

Kolban is correct. So in your case the answer would be:

Kolban是对的。所以在你的情况下答案是:

<div ng-repeat="item in company.details"> {{item.val}} </div>

{{item.val}}