【问题标题】:iCanHaz.js not loading a template when the page is loaded加载页面时 iCanHaz.js 未加载模板
【发布时间】:2023-03-18 06:48:01
【问题描述】:

我想在我的索引页加载后加载一个模板。我的索引页面包含:

<script src="site/introduction.html" type="text/html"></script>
<script src="js/lib/jquery-1.6.1.js" type="text/javascript"></script>
<script src="js/lib/ICanHaz.js" type="text/javascript"></script>
<script src="js/app/main2.js" type="text/javascript"></script>    

并且 main2.js 包含:

$(function() {
   var introduction_html = ich.introduction();
   $('#pm').html(introduction_html.filter('#introduction'));
});

没有找到介绍模板!即使我在调用 ich.grabTemplates() 之前使用它,它也不起作用。

我该如何解决这个问题?

introduction.html 包含:

<html>
<head>
<style type="text/css">
P.submit {text-align: left}
</style>
</head>

<body>

<div id="introduction">

<p>The tool can now guide you, step by step, through this procedure, beginning when you click on the "start" button below.</p>

<form action="">
<p class="submit"><input  type="submit" value="Start" /></p>
</form>

</div>

</body>
</html>

【问题讨论】:

  • @ThomasClayson,你的意思是 我可以危害控制台输出?
  • 我收到错误 Object # has no method 'introduction'
  • 能把introduction.html的内容贴出来吗?
  • 在调用ich.introduction之后会调用抓取模板的ajax回调... 怎么同步这些东西?
  • 应该这样定义模板: ?

标签: jquery icanhaz.js


【解决方案1】:

问题是远程模板是由 ICanHaz 异步抓取的,并且在我想使用它们来呈现页面时它们不可用。

我找到了两种不同的解决方案:

1) 使用脚本标签直接在页面中定义模板。这对我来说有点难看。

2) 使 ICanHaz 调用同步。如果您的模板很少,这是一个合理的权衡。我将这段代码更改为:

        $.ajax({url: script.prop('src'), dataType: 'text',

        $.ajax({async: false, url: script.prop('src'), dataType: 'text',

这就是诀窍。

【讨论】:

    【解决方案2】:

    做一个ich.refresh()来加载用ajax加载的模板

    【讨论】:

      猜你喜欢
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 2013-04-15
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多