The applet dynamically adds data and displays it

1. Get data traversal display through the background interface
<view class='comment_content' wx:for='{{comment}}' wx:for-item='item'>
<view class='comment_user'>
<image src='{{item.user_photo}}'></image>
<view>{{item.user_nick}}</view>
</view>
<view class='comment_info'>{{item.content}}</view>
<view class='get_comment'>
<view class='get_comment_info' catchtap='changeimg' data-index='{{index}}'>
<image src='./[email protected]' class='zan' wx:if="{{item.like_status==1}}"></image>
<image src='./[email protected]' class='zan' wx:else></image>
<view>{{item.like_count}}</view>
</view>
</view>
</view>
2. Leave a comment
<view class='to_talk' wx:if='{{talk}}'>
<view class='take_star' wx:if="{{second_p}}">
<view>Star Rating:</view>
<star key='{{num}}' is_click='{{is_click}}' bindincrement='incrementTotal'></star>
</view>
<view class='take_feel'>
<textarea class='input_feel' bindinput="bindTextAreaBlur" placeholder="Please share your feelings" value='{{feel}}'></textarea>
<button class='isok' catchtap='talk_feel'>确认</button>
</view>
</view>
3. Send the comments to the database through the interface and display them on the page
In the callback function success, define an object to add to the comment for display
console.log('Added successfully');
let id = res.data.data;
let newComment = {
content: that.data.feel,
id: id,
like_count: 0,
like_status: 0,
sec_comm_count: '',
user_nick: userInfo.user_nick,
user_photo: userInfo.user_photo,
second: [],
};
console.log(newComment)
 //It should be noted here that the initial value of arr1 is 'that.data.comment', which cannot be empty
let arr1 = that.data.comment;
arr1.unshift(newComment);
that.setData({
comment: arr1
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325206597&siteId=291194637