1

ちなみに、テンプレートソリューションとしてjtemplates(jqueryプラグイン)を使用しています。私はasp.netupdatepanelsをこれに置き換えました、そして私の神はなんとスピードブースターです。ただし、私が抱えている問題は、このテンプレートシステムを使用して記事の下にユーザーコメントを読み込んでいることです。私は次のようにテンプレートを処理しています:

function ApplyTemplate(result) {
if (result.d.length == 0) {
    $('#comments_empty').show();
}
else {
    var msg = (typeof result.d) == 'string' ? eval('(' + result.d + ')') : result.d;
    $('#comments_container').setTemplate($("#comments_template").html());
    $('#comments_container').processTemplate(msg);
    $('#comments_empty').hide();
}
$('#loading').hide();

}

これは問題なく動作しますが、私が今望んでいることは達成できません。新しいアイテムを追加したい(古いアイテムに[もっとコメントを表示]というボタンがあるため。だから、私は次の項目を使用できると思っていました。

var html = $('#comments_container').processTemplate(msg).toString();

次に、HTMLをそのコンテナまたは別のコンテナに追加しますが、それは機能しません。申し訳ありませんが、私はjquery / javascriptの専門家ではありませんが、誰かが解決策を知っていることを願っています。

お時間をいただきありがとうございます。よろしく、マーク

4

1 に答える 1

3

jtemplatesプラグインの詳細も、テンプレートがどのように見えるかわからないので、これは暗闇の中でのショットのようなものです。

これを試して:

function ApplyTemplate(result) {
  if (result.d.length == 0) {
    $('#comments_empty').show();
  } else {
    var
      $commentsContainer = $('#comments_container'),
      msg = ((typeof result.d) == 'string' ? eval('(' + result.d + ')') : result.d),
      old = $commentsContainer.html();
    $commentsContainer.setTemplate($("#comments_template").html());
    $commentsContainer.processTemplate(msg);
    $commentsContainer.prepend(old);
    $('#comments_empty').hide();
  }
  $('#loading').hide();
}
于 2010-09-29T15:46:43.613 に答える