Backbone.js 主干.布局管理器和把手模板引擎
我正在使用backbone.layoutmanager项目: 可以有人请张贴一个样本与车把模板引擎? 是否包含修改后的app.js文件和实例视图 我已经按照说明进行了操作,我有点困惑在实例级别和全局级别应该做什么。 我不断收到模板上没有“匹配”方法的错误消息Backbone.js 主干.布局管理器和把手模板引擎,backbone.js,javascript-framework,handlebars.js,backbone-views,Backbone.js,Javascript Framework,Handlebars.js,Backbone Views,我正在使用backbone.layoutmanager项目: 可以有人请张贴一个样本与车把模板引擎? 是否包含修改后的app.js文件和实例视图 我已经按照说明进行了操作,我有点困惑在实例级别和全局级别应该做什么。 我不断收到模板上没有“匹配”方法的错误消息 谢谢您修改后的app.js将与以下内容一起使用: define([ "jquery", "underscore", "backbone", "handlebars", "plugins/backbone.layoutm
谢谢您修改后的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>
您修改后的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>
把代码发出去看看,可能是可以帮你把代码发出去看看,可能是可以帮你