如何从属性访问该项目

时间:2018-02-22 07:17:57

标签: jquery json

<ion-item
  class="item-icon-left item-icon-right item-avatar"
  ng-repeat="note in taskDetails.notes track by note.note_id"
  ng-click="viewNote(note)">
  <i ng-show="note.status.name==Open" class="icon ion-ios-circle-outline"></i>
  <i ng-show="note.status.name!=Open"class="icon ion-ios-checkmark-outline"></i>
  <h2>{{note.note}}</h2>
  <p>{{note.created_by}}</p>
  <i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>

想要访问&#34;原创&#34;来自sku列表。但它返回未定义的原始。不确定它出错的地方&gt;。&lt;感谢快速帮助

2 个答案:

答案 0 :(得分:0)

尝试使用json["original"]

进行访问
var json =    {
  "label": "",
  "sku": "true",
  "xxx": {
    "promo": "",
    "specs": [],
    "original":"300.00"
  },
  "xxx": {
    "promo": "",
    "specs": [],
    "original":"350.00"
  },
  "xxx": {
    "promo": "",
    "specs": [],
    "original":"400.00"
  },

  "promo": "",
  "promo-img": "",
  "specs": [],
  "original":"350.00"
}


if(json["original]){
 object += '<div class="original-price">'+ json["original"] +'</div>';

答案 1 :(得分:0)

这是访问该属性的简单方法:

var json =    {
  "label": "",
  "sku": "true",
  "xxx": {
    "promo": "",
    "specs": [],
    "original":"300.00"
  },
  "xxx": {
    "promo": "",
    "specs": [],
    "original":"350.00"
  },
  "xxx": {
    "promo": "",
    "specs": [],
    "original":"400.00"
  },

  "promo": "",
  "promo-img": "",
  "specs": [],
  "original":"350.00"
}

var object='';
if(json["original"]){
object += '<div class="original-price">'+ json["original"] +'</div>';
console.log(object);
}