1

backbone.layoutmanager プロジェクトを使用しています: https://github.com/tbranyen/backbone.layoutmanager#readme

ハンドルバー テンプレート エンジンを使用したサンプルを投稿してもらえますか? 変更された app.js ファイルとインスタンス ビューが含まれていますか?

私は指示に従いましたが、インスタンス レベルとグローバルで何をすべきか少し混乱しています。テンプレートに「has no method 'match'」というエラー メッセージが表示され続けます。

ありがとう

4

1 に答える 1

5

変更した app.js は、次のように動作します。

define([
  "jquery",
  "underscore",
  "backbone",
  "handlebars",
  "plugins/backbone.layoutmanager"
],
function($, _, Backbone, Handlebars) {
  "use strict";

  var JST = window.JST = window.JST || {};

  Backbone.LayoutManager.configure({
    paths: {
      layout: "path/to/layouts/",
      template: "path/to/templates/"
    },

    fetch: function(path) {
      path = path + ".html";

      if(!JST[path]) {
        $.ajax({ url: "/" + path, async: false }).then(function(contents) {
          JST[path] = Handlebars.compile(contents);
        });
      }

      return JST[path];
    }

    // It is not necessary to override render() here.
  });

  var app = {
    // Define global resources here.
  };

  return _.extend(app, Backbone.Events);
});

ビューの例:

var SampleView = Backbone.View.extend({
  template: "path/to/sample/template",

  // Override this for fine grained control of the context used by the template.
  serialize: function() {
    return {
      property: 1,
      anotherProperty: 2
    };
  }

  // No need to override render() for simple templates.
});

ビューに関連付けられたテンプレート:

<div>
  <h2>{{property}}</h2>
  <h2>{{anotherProperty}}</h2>
</div>
于 2012-07-14T05:55:07.490 に答える