⼩程序动态增加按钮组件
这⾥的⼩程序动态加载是以按钮为例,主页⾯点击不同的按钮进⼊不同的⼦页⾯中,根据主页⾯的title来动态加载⼦页⾯按钮的数量以及值。
效果图:
wxml⽂件(注意wx:key="item"要写,不然它会有警告):
<!--pages/plan/plans/plans.wxml-->
<view class="className" wx:for="{{array}}" wx:key="item">
<button class="items" id="{{stv.id[index]}}">{{item.name}}</button>
</view>
这⾥起关键作⽤的是wx:for,这⾥是循环。
wxss⽂件:
/* pages/plan/plans/plans.wxss */
.items {
background-color: rosybrown;
width:60%;
}
js⽂件:
// pages/plan/hot/hot.js
Page({
data: {
},
onLoad: function (options) {
var that = this;
var arr = new Array();
if (options.title == "热门") {
var location1 = { name: "1" };
var location2 = { name: "2" };
var location3 = { name: "3" };
var location4 = { name: "4" };
var location5 = { name: "5" };
var location6 = { name: "6" };
arr.push(location1);
arr.push(location2);
arr.push(location3);
arr.push(location4);
arr.push(location5);
arr.push(location6);
console.log("OK");
} else {
var location1 = { name: "2" };
var location2 = { name: "4" };
var location3 = { name: "5" };
arr.push(location1);
arr.push(location2);
arr.push(location3);
}
wx.setNavigationBarTitle({title:'创建新计划--'+options.title});
success: function (res) {
that.setData({
//view
className_height: res.windowHeight / arr.length,
javascript动态效果//btn
array: arr,
})
}
})
},
})
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。