<button id='Purpose' class="mui-btn mui-btn-block" type='button'>选择</button>
<div id='purposeResult'></div>
<script>
(function($, doc) {
var userPicker = new $.PopPicker();
userPicker.setData([{
value: 'ywj',
text: '董事长 叶文洁'
}, {
value: 'aaa',
text: '总经理 艾AA'
}, {
value: 'lj',
text: '罗辑'
}, {
value: 'ymt',
text: '云天明'
}]);
userPicker.setData(arr);
var userResult = doc.getElementById('purposeResult');
doc.getElementById('Purpose').addEventListener('tap', function(event) {
userPicker.show(function(items) {
- **console.log(JSON.stringify(items));***
userResult .innerText = JSON.stringify(items[0]);
});
}, false);
})(mui, document);
</script>
多次点击确认按钮后的测试结果:
某次返回了一个空对象
[{"value":"ywj","text":"董事长 叶文洁"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{"value":"ymt","text":"云天明"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{"value":"ywj","text":"董事长 叶文洁"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{"value":"aaa","text":"总经理 艾AA"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{"value":"ymt","text":"云天明"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{"value":"ywj","text":"董事长 叶文洁"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{"value":"lj","text":"罗辑"}] at js/CentrifugeInfo/CentrifugePurpose.js:66
[{}] at js/CentrifugeInfo/CentrifugePurpose.js:66
1 个回复
h***@126.com (作者)
//判断是否是{}
function isEmptyObject(e) {
var t;
for (t in e)
return !1;
return !0
}
showUserPickerButton.addEventListener('tap', function(event) {
userPicker.show(function(items) {
if(!isEmptyObject(items[0])){
Purpose.innerText = items[0].text;
purposeResult.innerText = JSON.stringify(items[0]);
}else{
//返回 false 可以阻止选择框的关闭
return false;
}
});
}, false);
不知道这个bug是不是只有我遇到了,也可能是我书写不规范。
反正我现在是给了个判断空对象的动作,如果空对象就禁止修改并且阻止选择框关闭