Small micro-channel program (wx: for) traverse the object

Recently toss small micro-channel program, encountered such a situation: the back-end returns a key-value data objects, you need to traverse the object of key-value, and then render the view. Like this:

{
  '2018-1-9':{
      address: '....',
      name: '....'
  },
  '2018-1-10':{
    address: '....',
    name: '....'
  },
  '2018-1-11':{
    address: '....',
    name: '....'
  } 
}

Also encountered this situation, there are three solutions:

  1. Let the back-end interface to change it;
  2. To write their own functions, the object becomes an array, then setData;
  3. Direct traverse the object.

The following is an example of the third method:

//wxml
<view wx:for="{{obj}}" wx:for-index="key"  wx:for-item="value">

{{key}} : {{value.address}}

</view>
//js
data:{
    obj: {...}
}
渲染出的结果如下:
<view> 2018-1-9 : ...</view>
<view> 2018-1-10 : ...</view>
<view> 2018-1-11 : ...</view>

When wx: time for traversing the object, wx: for-index will be the object key, wx: for-item object's value will be
micro-channel applet document does not mention traverse the object, in the micro-letter code above the developer tools V1.02 test.

Guess you like

Origin www.cnblogs.com/liliuyu/p/11865063.html