1.wx.request中的數(shù)據(jù)加載到頁(yè)面
錯(cuò)誤方式:
<pre>
var that = this;
wx.request({
url:app.globalData.url.api.home,
success: function(res) {
var a= res;
//這樣直接賦值并不會(huì)把數(shù)據(jù)渲染到頁(yè)面上的 不過 0.9版本的時(shí)候這樣做是可以的
that.data.a=a;
}});
</pre>
正確方式:
<pre>
that.setData({
a:a;
});
</pre>
2.data-XX 數(shù)據(jù)存取
官方文檔中的錯(cuò)誤示范(個(gè)人覺得):
正確方式 :
正確的dataset的值是放在currentTarget中的巍沙,用targer時(shí)常會(huì)取不到值
應(yīng)該這樣:event.currentTarget.dataset來獲取dataset
3.小程序post寫法
這點(diǎn)在小程序文檔中沒有解釋清楚
<pre>
wx.request({
url: app.globalData.server + '/cart/list.do',
header: { "content-type": "application/x-www-form-urlencoded" },
method: "POST",
data: Util.json2Form({ cartId: app.globalData.cartId}),
success:function(){}
})
</pre>
json2Form方法
<pre>
function json2Form(json) {
var str = [];
for (var p in json) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
}
return str.join("&");
}
</pre>