赞
踩
跳转页面传递参数
- var selectWorker = JSON.stringify(selectWorker);
- uni.navigateTo({
- url: '../recordForm/recordForm?selectWorker=' + selectWorker
- })
- onLoad(option) {
- console.log(option)
- var _this = this;
-
- // 选中的工人
- var selectWorker = JSON.parse(option.selectWorker);
- var workerIdsArray = [];
- for (var i = 0; i < selectWorker.length; i++) {
- workerIdsArray.push(selectWorker[i].id);
- }
- var workerIds = workerIdsArray.join(',');
- console.log(workerIds);
- _this.selectWorker = selectWorker;
- _this.workerIds = workerIds;
- },
报错提示
SyntaxError:Unexpected end of JSON input
原因:若对象的参数或数组的元素中遇到地址中包括?& - _ . ! ~ * ' ( )等特殊符号时,对象/数组先要通过JSON.stringify转化为字符串再通过encodeURIComponent编码,接收时,先通过decodeURIComponent解码再通过JSON.parse转换为JSON格式的对象/数组。
修改如下:
- var selectWorker = JSON.stringify(selectWorker);
- uni.navigateTo({
- url: '../recordForm/recordForm?selectWorker=' + encodeURIComponent(selectWorker)
- })
- onLoad(option) {
- console.log(option)
- var _this = this;
-
- // 选中的工人
- var selectWorker = JSON.parse(decodeURIComponent(option.selectWorker));
- var workerIdsArray = [];
- for (var i = 0; i < selectWorker.length; i++) {
- workerIdsArray.push(selectWorker[i].id);
- }
- var workerIds = workerIdsArray.join(',');
- console.log(workerIds);
- _this.selectWorker = selectWorker;
- _this.workerIds = workerIds;
- },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。