小程序传递对象数组
其他数据格式暂时不知道,我的数据主要是对象数组格式,传递的时候总是获取不到数据。所以网上找了好多没有具体方案。自己写了一下。仅供参考!
arraylist2 是一个数组,数据格式是[{“id”,1},{“content”,”我的”}]
格式差不多就是这样 然后将它JSON.stringify()传递一下
wx .navigateTo ({
url : ‘../textcontent/textcontent?arraylist2=’ + JSON .stringify (that .data .arraylist2 ),
success : function (res ) {
console .log ( “成功回调” ,res );
},
fail : function (res ){
console .log ( “失败回调” ,res );
}
})
在下一个页面 获取值然后JSON.aprse()转换成json对象
data : {
arraylist : “”
},
onLoad : function (options ) {
console .log ( “options” , options .arraylist2 .title );
//var array = options.arraylist2.split(“,”);
var array = JSON .parse (options .arraylist2 );
this .setData ({
arraylist : array
})
console .log ( “arraylist” , this .data .arraylist );
},
在需要数据的页面就可以获取{ {arraylist.title}}
< view class= “t-bg tx-l uinn” style= ‘text-indent:40rpx;’ >{ {arraylist.title}} </ view >
< view class= “t-gra tx-l uinn ulh-a” style= ‘text-indent:40rpx;’ >{ {arraylist.content}} </ view >
ok
还没有评论,来说两句吧...