小编Rch*_*ani的帖子

刷新页面时,使用pushState的Backbone路由不起作用

我有一个简单的路由器:

Erin.Router = Backbone.Router.extend({
    initialize: function() {
        Backbone.history.start({pushState: true});
    },
    routes: {
        '' : 'index',
        'project/:img' :'project',
    },
    index: function() {
        var galleryView = new Erin.GalleryView();
    },
    project: function(img) {
        console.log(img);
    }
}); 
Run Code Online (Sandbox Code Playgroud)

Erin.GalleryViewis 的模板(认为​​可能存在问题):

<script type="text/template" id="gallery-grid">
        <a href="/project/<%= id %>">
            <img src="<%= thumbnail %>" />
            <span class="desc">
                <div class="desc-wrap">
                    <p class="title"><%= title %></p>
                    <p class="client"><%= client %></p>
                </div>
            </span>
        </a>
    </script>
Run Code Online (Sandbox Code Playgroud)

GalleryView和GalleryItem代码.

Erin.GalleryItem = Backbone.View.extend({
    tagName: 'div',
    className: 'project-container',
    //Grab the template html
    template: _.template($('#gallery-grid').html()),
    //Set up …
Run Code Online (Sandbox Code Playgroud)

javascript backbone.js backbone-routing

3
推荐指数
1
解决办法
1580
查看次数

标签 统计

backbone-routing ×1

backbone.js ×1

javascript ×1