提交 e294fa69 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

fix(getDeviceInfo): 修复类型调整后导致的类型错误

上级 4a159e16
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
}}</view> }}</view>
</view> </view>
<view class="uni-list-cell-db"> <view class="uni-list-cell-db">
<text style="width: 100%;">{{ item.value == '' ? '未获取' : item.value }}</text> <text style="width: 100%">{{
item.value == "" ? "未获取" : item.value
}}</text>
</view> </view>
</view> </view>
</view> </view>
...@@ -50,25 +52,25 @@ ...@@ -50,25 +52,25 @@
getDeviceInfo: function () { getDeviceInfo: function () {
const res = uni.getDeviceInfo(); const res = uni.getDeviceInfo();
// 获取像素比, 供截图对比使用 // 获取像素比, 供截图对比使用
setDevicePixelRatio(res.devicePixelRatio !== null ? parseFloat(res.devicePixelRatio!) : 1) setDevicePixelRatio(res.devicePixelRatio !== null ? res.devicePixelRatio! : 1)
this.items = [] as Item[]; this.items = [] as Item[];
const res_str = JSON.stringify(res); const res_str = JSON.stringify(res);
const res_obj = JSON.parseObject(res_str); const res_obj = JSON.parseObject(res_str);
const res_map = res_obj!.toMap(); const res_map = res_obj!.toMap();
let keys = [] as string[] let keys = [] as string[]
res_map.forEach((_, key) => { res_map.forEach((_, key) => {
keys.push(key); keys.push(key);
}); });
keys.sort().forEach( key => { keys.sort().forEach(key => {
const value = res[key]; const value = res[key];
if(value != null){ if (value != null) {
const item = { const item = {
label: key, label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value) value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
} as Item; } as Item;
this.items.push(item); this.items.push(item);
} }
}); });
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册