backbone.layoutmanager和车把的模板引擎
问题描述:
我使用的backbone.layoutmanager项目: https://github.com/tbranyen/backbone.layoutmanager#readmebackbone.layoutmanager和车把的模板引擎
可有人请张贴与车把模板引擎的样本?包含修改后的app.js文件和实例视图的 ?
我遵循指示,我有点困惑我应该在实例级别和全局中做什么。 我不断收到“我的模板有没有一种方法‘匹配’ERR消息
感谢
答
你修改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-09 14:56:50