ICanHaz未检测到模板

时间:2012-11-06 03:48:46

标签: javascript template-engine icanhaz.js

我已经检查过这个主题的其他帖子,但没有一个符合我的问题。这是我的模板的代码:

<script id ="postingcell" type="text/html">
    <li class="postinglistcell">
        <div class = "postinfowrapper">
            <table class="centermargins">
                <tr>
                    <td>
                        <div class="posttitle">{{Title}}</div>
                    </td>
                </tr>
            </table>
        </div>
    </li>
</script>

以下是我称之为ICH的代码:

$(document).ready(function() {
    var p = ich["postingcell"](thisobj);
});

我可能会收到错误,告诉我ich["postingcell"]未定义,但它已经在上面的脚本标记中。有谁知道我在这里做错了什么?

1 个答案:

答案 0 :(得分:3)

ICanHaz也使用jQuery进行设置。一个可能的原因是您的代码在 ich.grabTemplates()调用之前运行。

if (ich.$) {
    ich.$(function () {
        ich.grabTemplates();
    });
}

您可以尝试在代码中调用 ich.grabTemplates()

$(document).ready(function() {
    ich.grabTemplates();
    var p = ich["postingcell"](thisobj);
});
相关问题