【问题标题】:Rendering a local template with Sammy.js使用 Sammy.js 渲染本地模板
【发布时间】:2011-07-10 21:49:10
【问题描述】:

我正在将 sammy 用于需要呈现存储在页面中的内联模板的 Web 应用程序。我正在使用脚本标记来包含标记,即 haml。

是否有一种好的、惯用的方式来呈现不是通过 ajax 请求加载的模板?我有一个解决方案,但我对此并不满意。 $('#start_haml') 是包含标记的脚本元素,$('#sammy_main') 是要渲染到的容器。

app.get '#/', (context) ->

context.load($('#start_haml')).then((data) ->
  context.interpolate(data, {helpers: view_helpers})
).replace('#sammy_main')

【问题讨论】:

    标签: sammy.js


    【解决方案1】:

    感谢 Aaron Quint answering me on the Sammy.js mailing list

    答案很简单,但值得留在此处,因为文档中没有提及。

    context.render($('#start_haml'), {helpers: view_helpers})
      .replace '#sammy_main'
    

    注意。 render() 的第二个参数是视图数据。

    【讨论】:

      【解决方案2】:

      对我来说,这很有效:

      this.use('Template', "[object HTMLScriptElement]"); // If not view data are not rendered
      [...]
      var template = $('#tmpInmuebleDetalle')[0];
      this.partial(template);
      

      【讨论】:

        猜你喜欢
        • 2023-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-08
        相关资源
        最近更新 更多