BlackBerry-10 Webworks Javascript错误

时间:2012-12-27 06:12:06

标签: javascript html5 blackberry-webworks blackberry-10 ripple

我正在使用webworks框架为 blackberry 10 os 开发一个应用程序..当我在 bb10 dev alpha设备中运行以下代码时,我得到一个控制台日志找不到恢复变量。我的html文件包含一个bbui按钮,并在onclick上调用函数恢复。 javascript代码发布在下面..

        var text="FN: Mohammed;Shinoys\n";
        var a=new Array();

        a=["N","FN","NICKNAME","TEL;CELL",
           "TEL;TYPE=CELL","TEL;HOME","TEL;TYPE=HOME",
            "EMAIL;HOME","EMAIL;TYPE=HOME","EMAIL;WORK",
            "EMAIL;TYPE=WORK","ADR;HOME","ADR;TYPE=HOME",
            "LABEL;HOME","LABEL;TYPE=HOME","ADR;WORK",
            "ADR;TYPE=WORK","LABEL;WORK","LABEL;TYPE=WORK","NOTE","ORG","TITLE"];

        function restore()
        {
         var contacts = blackberry.pim.contacts;
        var contactAddress = contacts.ContactAddress;
        var contactField = contacts.ContactField;
        var name = new Object();
        var ename;
        var bb= new Object();
        var tt= new Object();
        var textarray=new Array();
        var arr=new Array();
        var s=new Array();
        var str,check,string;
        var textarray2=new Array();
        var newcontact = new Object();
        console.log("entered function");
        newcontact=contacts.create({name:{givenName:"Hello",familyName:"World"}});
        console.log("NEWCONTACT: " + newcontact.ContactName.givenName);

        for(var k=0;k<a.length;k++)
        {
            str=a[k];
            check=text.match(RegExp("^"+str+":","i"));
            if(check===null)
            continue;
        //alert(check);
            console.log(str);
            string=text.replace(RegExp("^"+str+":","i"),"");
            console.log("string"+string);

            switch(k)
            {case 0 : 
                        arr=string.split(";");
                        console.log("name "+arr);
                        newcontact.ContactName.familyName=arr[0];
                        newcontact.ContactName.givenName=arr[1];
                        break;
             case 1 :   console.log("ASDADAD");
                        newcontact.ContactName.formatted=string;
                        console.log("FULL name "+arr);
                        ename=string;
                        break;
             case 2 : newcontact.ContactName.phoneticGivenName=string;
                        break;
             case 3 : 
                        case 4 : tt={type:contactField.MOBILE,value:string};
                        newcontact.phoneNumbers[newcontact.phoneNumbers.length]=tt;
                        break;
              case 5 :
              case 6 : tt={type:contactField.HOME,value:string};
                        newcontact.phoneNumbers[newcontact.phoneNumbers.length]=tt;
                        break;
              case 7 : 
              case 8 :  tt={type:contactField.HOME,value:string};
                        newcontact.emails[newcontact.emails.length]=tt;
                        break;
              case 9 : 
              case 10 : tt={type:contactField.WORK , value:string};
                        newcontact.emails[newcontact.emails.length]=tt;
                        break;
              case 11 : 
              case 12 : s=string.split(";");
                        bb={type:contactAddress.HOME,streetAddress:s[2],locality:s[3],region:s[4],postalCode:s[5],country:s[6]};
                        newcontact.addresses[newcontact.addresses.length]=bb;
                        break;
              case 13 : 
              case 14 : if(newcontact.addresses[0].type===contactAddress.HOME)
                        newcontact.addresses[0].formatted=string;
                        if(newcontact.addresses[1].type===contactAddress.HOME)
                        newcontact.addresses[1].formatted=string;
                        break;
              case 15 : 
              case 16 : s=string.split(";");
                        bb={type:contactAddress.HOME,streetAddress:s[2],locality:s[3],region:s[4],postalCode:s[5],country:s[6]};
                        newcontact.addresses[newcontact.addresses.length]=bb;
                        break;
              case 17 : 
              case 18 :if(newcontact.addresses[0].type===contactAddress.WORK)
                        newcontact.addresses[0].formatted=string;
                        if(newcontact.addresses[1].type===contactAddress.WORK)
                        newcontact.addresses[1].formatted=string;
                        break;
              case 19 :newcontact.note=string;
                        break;
              case 20 :newcontact.organizations[0]={name:string};
                        str=a[k+1];
                        check=text.match(RegExp("^"+str,"i"));
                        if(check!==null)
                        {string=text.replace("^"+str+":","");
                        newcontact.organizations[0]={title:string};
                        }
                        break;
            }

        } 
           newcontact.save(onSaveSuccess,onSaveError);
        }

        function onSaveSuccess(contact) {
           alert("Contact saved: " + contact.name.givenName);
        }
        function onSaveError(error) {
           alert("Contact : save failed: " + error.code);
        }

感谢任何帮助。 关心shinoys222

1 个答案:

答案 0 :(得分:0)

从问题描述中,如果页面找不到恢复功能,则表示此JavaScript代码未正确加载。建议您检查以确保从屏幕正确引用JS文件,如下所示:

<div data-bb-type="screen" data-bb-indicator="true">
    <script id="myJS" src="js/my.js"></script>

</div>