2017-09-04 75 views
0

我想在我的視圖中遍歷JSON數組,但我只想顯示具有非空字符串值的鍵。如何僅顯示數組中的非空字符串值

design: 
{name: "ux", value: "3", $$hashKey: "object:5198"} 
{name: "graphic", value: "", $$hashKey: "object:5199"} 
{name: "concept", value: "4", $$hashKey: "object:5200"} 
{name: "photoshop", value: "", $$hashKey: "object:5201"} 
{name: "illustrator", value: "5", $$hashKey: "object:5202"} 
{name: "inDesign", value: ""} 
{name: "afterEffects", value: ""} 
{name: "premierePro", value: "1"} 

我怎麼會只得到了數組的按鍵,同時通過遍歷數組,只表明有真正價值的人。

當前的代碼,我有是:

<div class="six columns"> 
         <div ng-repeat="skill in employeeDetails.design | limitTo:5:0 | filter:{value:'! '}"> 
          {{ skill.name | capitalize }} {{ skill.value }} 
         </div> 
        </div> 

任何幫助,將不勝感激!

+1

只需使用|過濾:{值:'!! '} – Vivz

回答

1

您可以在此情況下,使用ng-if

<div class="six columns"> 
    <div ng-repeat="skill in employeeDetails.design | limitTo:5:0" ng-if="skill.value !== '' "> 
      {{ skill.name | capitalize }} {{ skill.value }} 
     </div> 
</div> 

或更改filter

<div class="six columns"> 
     <div ng-repeat="skill in employeeDetails.design | limitTo:5:0 | filter:{value:'!! '}" ng-if="skill.value !== '' "> 
       {{ skill.name | capitalize }} {{ skill.value }} 
      </div> 
    </div> 
+0

謝謝你的工作!我過去在模塊中創建一個過濾器來思考它。 – qasimalbaqali

+0

請接受答案,因爲這對其他訪問者很有用。 –

+0

會做,它有一個時間限制壽:) – qasimalbaqali

相關問題