0

私はsymfony2.0に次のような小枝のパス関数で生成されたリンクを持っています:

<a id="aBtn" href="{{ path("SomeController_someControllerAction",{'section_id':
    section_id, 'period_id': period.getId }) }}>A link</a>

また、ユーザーがページのセクションを変更するたびに、生成されたURLの「section_id」部分を更新するJavaScriptもあります。

function updateSectionId(id){
  var aBtn = $("#aBtn");
  var href = aBtn.attr('href');
  var splitted = href.split("/");
  splitted[splitted.length-2] = id; //My routing puts the period_id at that position
  //(Yes i know its pretty hardcoded...)
  aBtn.attr('href',splitted.join("/"));
}

確認しました。リンクは対応するsection_idで更新されます。

ただし、この要求を受け取るアクションをデバッグすると、常にsection_id=1を受け取ることがわかります。

public function newQuestionDialogAction($period_id, $section_id){
  //$period_id = 1 ALWAYS, regardless of href value on the link.

私は本当に無知です...私は小枝のルート生成に何かが欠けていますか?

編集:これがルート構成です

SomeController_someControllerAction:
    pattern: /{period_id}/section/{section_id}/someControllerAction
    defaults: { _controller: "SomeBundle:SomeController:someControllerAction" }
    requirements:
      _method: GET

EDIT2:この問題の原因は、サーバーへのajaxリクエストの実行に使用されるjquery-bootstrapプラグイン「Modal2」にあると思います。問題が見つかったらお知らせします。ありがとう!

https://github.com/Nikku/jquery-bootstrap-scripting

4

2 に答える 2

0

ブラウザのリンクを見てください。実際に正しいIDで新しいページに移動しますか?そうでない場合は、JavaScriptに問題があります。

于 2012-10-23T21:01:20.507 に答える
0

したがって、問題は確かに私のjavascriptにあり、解決策は恥ずかしいほど単純です。誰かがjqueryブートストラップライブラリで同じ問題に遭遇した場合に備えて、ここに投稿しています。

電話したら

$(document).controls()

すべての要素のすべてのクラス「open-dialog」が削除されるため、$(document).controls()を何度呼び出しても、onClickイベントが正しいhrefで更新されません。回避策は、$(document).controls()を再度呼び出す前に「open-dialog」クラスを追加することです。

$("#some-element").addClass("open-dialog");
$(document).controls();

したがって、私の場合、解決策はupdateSectionIdメソッドを更新することでした。

function updateSectionId(id){
  var aBtn = $("#aBtn");
  var href = aBtn.attr('href');
  var splitted = href.split("/");
  splitted[splitted.length-2] = id; //My routing puts the period_id at that position
  //(Yes i know its pretty hardcoded...)
  aBtn.attr('href',splitted.join("/"));
  //Add open-dialog class and call controls to reattach the href
  aBtn.addClass("open-dialog");
  $(document).controls();
}
于 2012-11-17T03:47:25.517 に答える