1

私の目標: div にコンテンツを入力するジョブのウィジェットを作成しています。エラーが発生するため、情報を実行することさえできません: Uncaught Syntax Error: Unexpected Token Return

この関数を実行するオブジェクトを次のように作成しました。

function TreeView(){
    this.rebuild = contructRoot();
}

function constructRoot(){
    var resultant = ajax_Request();
    var content = $(resultant);

    var root = $("<div>");
    var root_nodes = ajax_Request("/startTreeAJAX");
    root_nodes.split("|");
    root.html(
        $("<div>").html(
            $("<ul>").append($('<li>').html(root_nodes[0])).append($("<li>").html(root_nodes[1]))
        )
    );
    root.find("li").click(function(){
        clickExpand(this);
    });

    return root.html();
}

基本的に要素の内容を返そうとしています。

4

3 に答える 3

6

の終了).click()ありません。関数定義を.}の後に終了することを忘れないでくださいreturn。予期しないトークンのような構文エラーが表示された場合は、その直前のものを調べて問題を見つけてください...

  root.find("li").click(function(){ 
     clickExpand(this);
  }); // <----

  return root.html();
}
于 2012-07-16T14:33:04.907 に答える
2

中括弧と括弧を確認してください。あなたはそれらのいくつかを見逃しています。

root.find("li").click(function () {
    clickExpand(this);
});  // <-- you're missing the `)` here
    return root.html();
} // <-- You're missing the `}` here

更新: 他の人が述べているように、このコードには他の問題があります。

root_nodes.split("|");

これは何もしません。それに設定する必要がありますroot_nodes

root_nodes = root_nodes.split("|");
var c = $('<li>').html(root_nodes[0]) + $("<li>").html(root_nodes[1]);

これはあなたが思っていることをしません。は+文字列を連結し、以下を返します。

"[object Object][object Object]"

.appendjQuery オブジェクト (または配列) を受け入れることができるので、次のようにすることをお勧めします。

var c = [$('<li>').html(root_nodes[0]), $("<li>").html(root_nodes[1])];
root.html($("<div>").html($("<ul>").append(c)));
于 2012-07-16T14:32:35.827 に答える
2

Javascript の split() メソッドは配列を返します。上記のコードでは、その配列を受け取って保存する必要があります。

root_nodes = root_nodes.split("|")
于 2012-07-16T14:32:49.087 に答える