1

am using JSRender in my application.

<html> 
<body> 
    {{for Comments}}  
        <input id="id_{{:CommentId}}" type="hidden" value="-1" />
        <textarea id="cmt_{{:TopicId}}" ......... />
    {{/for}}
</body>
</html>
<script type="text/javascript">
 $(document).ready(function () {

  //The below code gets executed / works fine.
  $('#cmt_{{:TopicId}}').bind('keyup keydown paste', function (e) {
    //my logic        
  });

  //This code doesnot work fine, instead of -1, it gives undefined.
  var rankAction = $("#id_{{:CommentId}}").val();
});        
</script>

i want the rankAction variable to give -1, whereas it returns undefined, why is it so?

Is it simply because id containing JSRendered value within them cant be read in Script coding?

Then why is the other part i.e. cmt{{:TopicId}} returning a value ?

Where is it wrong?

4

1 回答 1

1

堆叠溢出的人:我很抱歉将其作为“答案”,但评论不足以描述我的问题。

@ismail baig:jsrender 模板的调用如下:

// Render the template with the movies data and insert
// the rendered HTML under the "movieList" element
$( "#movieList" ).html(
    $( "#movieTemplate" ).render( movies )
);

请注意,该模式是一些 template.render(datalist) ,可以使用以下方式定义模板:

<script id="movieTemplate" type="text/x-jsrender">
    <div>
        {{:#index+1}}: <b>{{>name}}</b> ({{>releaseYear}})
    </div>
</script>

#movieList只是一个元素。 movies是一个javascript数组。我没有看到这三个项目:模板、数据列表,也没有在您的示例中调用渲染模板。

作为参考,请查看此页面并查看源代码以查看代码、模板和用法。

于 2013-07-30T12:14:24.190 回答