爱慕啼
爱慕啼
  • 发布:2015-09-21 11:10
  • 更新:2015-09-28 20:27
  • 阅读:2717

使用H5 的actionSheet点击后怎样得到绑定的值?

分类:MUI

比如怎样得到点击删除信息的那个tid

我想把服务器得到的数据绑定到actionSheet的每一个项上,然后点击得到绑定的值,传到后台。
但是用h5的actionSheet话怎么实现,使用h5的actionSheet主要是他可以跨webview,
可以跨webeivw的框框太少了?

难道只能用switch去分配每个事件吗?

document.getElementById("delete-btn").addEventListener('tap',function () {  
            var btnArray = [{title:"删除信息",style:"destructive",tid:"hh"}];  
            plus.nativeUI.actionSheet( {  
                cancel:"取消",  
                buttons:btnArray  
            }, function(e){  
                var index = e.index;  
                console.log(e.index);  
                var text = "你刚点击了\"";  
                switch (index){  
                    case 0:  
                        text += "取消";  
                        break;  
                    case 1:  
                        text += "删除信息";  
                                                 console.log(e.index);  
                        break;  
                }  
                info.innerHTML = text+"\"按钮";  
            } );  
        });
2015-09-21 11:10 负责人:无 分享
已邀请:
chender

chender - 与人为善

var map={删除:'hh',取消:'bb'};
.
.
.
alert(map[btnArray[index].title])

  • 爱慕啼 (作者)

    您好,用您这种方法报错。您可以就这个例子写一段获取tid的代码吗?


    Uncaught TypeError: Cannot read property 'title' of undefined at examples/actionsheet-plus.html:93


    document.getElementById("picture-btn").addEventListener('tap',function () {

    var btnArray = [{title:"拍照或录像",tid:'id1'},{title:"选取现有的",tid:'id2'}];

    plus.nativeUI.actionSheet( {

    title:"选择照片",

    cancel:"取消",

    buttons:btnArray

    }, function(e){

    var index = e.index;

    var text = "你刚点击了\"";

    console.log(btnArray[btnArray[index].title]);

    switch (index){

    case 0:

    text += "取消";

    break;

    case 1:

    text += "拍照或录像";

    break;

    case 2:

    text += "选取现有的";

    break;

    }

    info.innerHTML = text+"\"按钮";

    } );

    });

    2015-09-29 09:22

  • chender

    因为有个取消按钮,你改成 alert(map[btnArray[index+1].title])试一下

    2015-09-29 09:37

  • 爱慕啼 (作者)

    您好,使用console.log(btnArray[btnArray[index+1].title]);还是报错。

    Uncaught TypeError: Cannot read property 'title' of undefined at examples/actionsheet-plus.html:115


    我感觉您写的格式和官方Demo的格式不太一样?

    var btnArray = [{title:"删除信息",style:"destructive",tid:"hh"}];


    而您写的格式是

    var map={删除:'hh',取消:'bb'};

    alert(map[btnArray[index].title])

    那btnArray代表什么呢?

    2015-09-30 15:21

  • chender

    我不是这个意思,我是说额外定义一个map,然后你还是用你的btnAray去显示actionsheet,在点击事件里面alert(map[btnArray[index].title])

    2015-10-01 10:40

  • 爱慕啼 (作者)

    非常感谢

    2015-10-05 11:23

该问题目前已经被锁定, 无法添加新回复