0

代码片段:

var role=s[0].Role;// role contains string value 
dijit.byId("editRole").attr("Value",getRoleByName(role));

function getRoleByName(role)
{
    var roleVal;
    alert(role);
    switch(role)
    {
        case 'Basic User' :roleVal='1';break;
        case 'Network Operator' :roleVal='3';break;
        case 'System Administrator' :roleVal='5';break;
        case 'Custom Level 1' :roleVal='11';break;
        case 'Custom Level 2' : roleVal='12';break;
        default: roleVal='1';break;
    }
    return roleVal;
}

当我尝试调用其中包含 switch 语句的 Javascript 方法时,我在 IE8 中遇到错误,但在 Firefox 中工作正常。

开发人员工具中的错误:

method Error executing: function(/*Event*/ e){
    // summary:
    // Handler when the user activates the button portion.
    if(this._onClick(e) === false){ // returning nothing is same as true
        e.preventDefault(); // needed for checkbox
    } else if (this.type == "submit" && !this.focusNode.form){ // see if a nonform widget needs to be signalled
        for(var node=this.domNode; node.parentNode/*#5935*/; node=node.parentNode){
            var widget=dijit.byNode(node);
            if(widget && typeof widget._onSubmit == "function"){
                widget._onSubmit(e);
                break;
            }
        }
    }
}TypeError: Object doesn't support this property or method

谁能帮我这个?...如何克服这个问题?...

4

1 回答 1

0

您显示的错误与以下代码无关。正如 dojotoolkit-src 评论亲切地向您展示的那样,它与“用户激活按钮部分时的处理程序”功能有关。

应该解决这个问题

 // << Value is all lower case
 dijit.byId("editRole").attr("Value",getRoleByName(role)); 

还有一个带有'WTF'的更简洁的编码开关 - 我认为这可能是突出显示你正在尝试的语法 - 或者这些波浪线真的在你的代码中吗?

 // What are these back-tilds doing here?
 switch(role)``  
 {
      case 'Basic User'           : return 1
      case 'Network Operator'     : return 3
      case 'System Administrator' : return 5
      case 'Custom Level 1'       : return 11
      case 'Custom Level 2'       : return 12
      default:
           return 1
     // return works as your break does, it stops the switch
}

在修剪过程中说出您的击球问题?试试这个,不是所有的javascript引擎都实现了trim

if(typeof String.prototype.trim !== 'function') {
        String.prototype.trim = function() {
                return this.replace(/^\s+|\s+$/g, ''); 
        }
}
于 2012-07-21T14:56:31.167 回答