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 エンジンに実装されているわけではありません

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