Vue.js-如何显示所有属性键和嵌套的属性值?

问题描述

找不到更好的标题,我的问题很难用一句话形容。我试图遍历由某些第三方程序包生成的导入对象,但其结构有问题:

obj: {
  "name1": {
    "property1": "value1","property2": "value2",},"name2": {
    "property1": "value3","property2": "value4","name3": {
    "property1": "value5","property2": "value6",}
}

我不仅要显示property1property2,还要显示这些名称之前的名称

- name1
  value1
  value2

- name2
  value3
  value4

...

这是我到目前为止的代码

<ul>
  <li v-for="(item,i) in obj" :key="index">
    {{ item.property1 }}
    <br>
    {{ item.property2 }}
  </li>
</ul>

鉴于此对象的奇数结构,如何显示名称

JSFiddle

解决方法

只需在您的let sections: [(title: String,rows: [BaseViewModel])] func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell { let viewModel = sections[indexPath.section].rows[indexPath.row] let cell = let tableCell = tableView.dequeueReusableCell(withIdentifier: viewModel.cellIdentifier,for: indexPath) as? BaseTableViewCell tableCell?.setupWith(viewModel: viewModel) return tableCell ?? UITableViewCell() } 循环中添加def calcLoginTime(g): LoginFailTime = None for i,record in g.iterrows(): if record['Action']=='Login Fail': if not LoginFailTime: LoginFailTime = record['TimeStamp'] if record['Action'] == 'Login Successful': if LoginFailTime: df.loc[i,'TimeAfterLoginFailMins'] = 24*60*(record['TimeStamp'].day - LoginFailTime.day) + (record['TimeStamp'] - LoginFailTime).seconds//60 LoginFailTime=None df.index = pd.RangeIndex(0,len(df)) df['TimeAfterLoginFailMins']='' for i,UserAttepmts in df.groupby('UserID'): calcLoginTime(UserAttepmts.sort_values('TimeStamp',axis=0)) print(df) 属性并呈现它即可:

key
,

Object.keys()圈起对象键,并用另一个v-for显示键中的对象值

<script src="https://unpkg.com/vue"></script>

<div id="app">
  <ul>
    <li v-for="(item,i) in Object.keys(obj)" :key="index">
      {{ item }}
      <ul>
        <li v-for="(property,key) in obj[item]" :key="property">
          {{ key }} -> {{ property }}
        </li>
      </ul>
    </li>
  </ul>
</div>