小程序同一页面赋值Jso的数据并显示出来(完美案例)

目的:加载Api返回的Post的Json数据,并显示在界面表示出来。打通数据库到小程序到界面对应显示出来。

困难:

1.在Data中的数据如何在页面加载是赋值替换?

2.提供post的Data值还没有设置变量

<view class='mingpian' wx:for="{{arr}}" style="transform:translate(10px, 10px);" >

<image class='images'src="{{item.Photo}}"></image>

<view class='name'>{{item.Name}} <view class='position'>{{item.Position}}</view></view>

<view class='company'>{{item.Company}}</view>

</view>

///////////////////////

var that = this;

wx.request({

url: 'http://localhost:40637/api/values/',

data: {

Id: 1,

Name: 'xiaohong'

},

method: "POST",

dataType: JSON,

success: function (res) {

console.log(JSON.parse(res.data));

var value = JSON.parse(res.data);

that.setData({

arr:value

})

},

})

//////////////////////////////////////

.mingpian{

display: flex;

align-items:center;

justify-content:left;

width: 100%;

height: 100%;

}

.images

{

width: 60px;

height: 60px

}

.name

{

font-size: 20px;

}

.position

{

font-size: 15px;

}

.company

{

font-size: 16px;

}

配合案例使用:https://download.csdn.net/download/weixin_42401291/10775476

猜你喜欢

转载自blog.csdn.net/weixin_42401291/article/details/83900994