如何获得这个主心骨上班路线? [英] How to get this backbone route to work?
问题描述
具有使一航工程问题CI'm。我有一个项目列表视图,单个项目的HTML如下:
CI'm having problems with making one route works. I have list view with items, single item html looks like this:
<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="c" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-count ui-btn-up-c"><div class="ui-btn-inner ui-li"><div class="ui-btn-text">
<a href="#my_clients/1486" class="ui-link-inherit">
<h4 class="ui-li-heading">number/h4>
<span class="ui-li-count ui-btn-up-c ui-btn-corner-all">A</span>
</a>
</div>
<span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span>
</div>
</li>
我的路由器code:
my router code:
var AppRouter = Backbone.Router.extend({
routes:{
"": "login",
"login": "login",
"my_clients": "myClients",
"my_clients/:id": "myClientDetails"
},
initialize:function () {
// Handle back button throughout the application
$('.back').live('click', function(event) {
window.history.back();
return false;
});
this.firstPage = true;
},
login: function () {
this.changePage(new LoginView({ model: new User() }));
},
myClients: function() {
this.changePage(new MyClientsView({ model: new MyClientsCollection() }));
},
myClientDetails: function(id) {
var client = new Client({ id: id });
self = this;
client.fetch({
success: function(data) {
self.changePage(new MyClientDetailsView({ model: data }));
}
});
},
changePage:function (page) {
$(page.el).attr('data-role', 'page');
page.render();
$('body').append($(page.el));
var transition = $.mobile.defaultPageTransition;
// We don't want to slide the first page
if (this.firstPage) {
transition = 'none';
this.firstPage = false;
}
$.mobile.changePage($(page.el), {changeHash:false, transition: transition});
}
});
登录和MyClients页工作正常,但是当我点击列表视图项链接显示单个客户的详细资料我看得到我的Firebug的控制台和路由调用是行不通的。
Login and MyClients pages works ok, but when I click on link in list view item to show individual client details I see get call in my firebug console and route is not working.
我是什么失踪?
推荐答案
修改&LT; A HREF =#my_clients / 1486...&GT;
到&LT; A HREF =#/ my_clients / 1486...&GT;
(换句话说,添加 /
在#
)。
见例如: http://jsfiddle.net/theotheo/sz6y8/
Change <a href="#my_clients/1486"...>
to <a href="#/my_clients/1486"...>
(in other words, add /
after #
).
See the example: http://jsfiddle.net/theotheo/sz6y8/
这篇关于如何获得这个主心骨上班路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!