V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Backbone supplies structure to JavaScript-heavy applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface.
yakczh
V2EX  ›  Backbone.js

有用过Backbone的吗,backbone在不同路由跳转的时候可以从服务器取模板吗?还是说要所有的模板都要取回来?

  •  
  •   yakczh · 2012-12-27 16:30:34 +08:00 · 7119 次点击
    这是一个创建于 4109 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    1970-01-01 08:00:00 +08:00
    loddit
        1
    loddit  
       2012-12-27 23:05:33 +08:00
    从服务器取模板必然需要ajax加载,体验不够流畅,而往往前端模板都不是很复杂,好处也往往大于坏处,所以直接带上比较好。
    jackyz
        2
    jackyz  
       2012-12-28 10:51:19 +08:00
    简短回答:

    1,可以的。
    2,不用,不过这样最简单(代价也不大)。

    异步加载模版请自己放 google 找 backbone.marionette 的例子。
    yakczh
        3
    yakczh  
    OP
       2012-12-28 11:23:21 +08:00
    App.Controllers.Routes = Backbone.Controller.extend({
    routes: {
    "!/hello" : "hello",//使用#!/hello驱动路由
    },
    hello : function() { ... }
    });
    这样报错

    TypeError: Backbone.Controller is undefined
    [在此错误处中断]

    App.Controllers.Routes = Backbone.Controller.extend({
    lyuehh
        4
    lyuehh  
       2012-12-28 17:04:53 +08:00
    Backbone 0.5.3以后就没有Controller了,改叫Route了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3365 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 00:06 · PVG 08:06 · LAX 17:06 · JFK 20:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.