0
我是backbone.js的新手,現在我在backbone.js
項目中創建一個菜單。我在HTML文件中使用text.js
到環路數據並傳遞到視圖:在骨幹js中創建視圖和子路由器
<%
require(["jquery" ,
"webconfig",
"content"
],function($ , WebConfig, Content){
var content = new Content();
var contentType = deserializeJSONToObj(content.getContentType());
var str = '<ul>';
for(var i = 0; i < contentType.length ; i++){
str += '<div class="ulDiv"><ul class="footerUL"><li>'+contentType[i].Title+'</li>';
for(var j = 0; j < contentType[i].Contents.length ; j++){
str += '<li><a href="'+ contentType[i].Contents[j].ExpiredDayCount + '">' + contentType[i].Contents[j].Title + '</a></li>';
}
str += '</ul></div>';
}
str += '</ul>';
$(".containerFooterUL").append(str);
});
%>
這是實體模型的結果(注:#服務/ teaminstall,#服務/索尼....是動態的):
<div class="ulDiv">
<ul class="footerUL">
<li>SERVICES</li>
<li><a href="#service/teaminstall">Team Install</a></li>
<li><a href="#service/sony">Sony Simulator</a></li>
</ul>
</div>
<div class="ulDiv">
<ul class="footerUL">
<li>Account</li>
<li><a href="#account/cash">Cash</a></li>
<li><a href="#account/cash">Cash</a></li>
</ul>
</div>
這是路由器:
var AppRouter = Backbone.Router.extend({
routes: {
"service" : "serviceAction",
"service/serviceTag" : "serviceTagAction",
"service/serviceSurvey" : "serviceSurveyAction",
"*actions": "defaultRoute"
}
});
var app_router = new AppRouter;
app_router.on('route:serviceAction', function(){
if(window.currentSection)
window.currentSection.remove();
window.currentSection = new Service({});
$("#webbodycontainer").html(window.currentSection.$el);
window.currentSection.render();
});
app_router.on('route:serviceTagAction', function(){
if(window.currentSection)
window.currentSection.remove();
window.currentSection = new ServiceTagLookUp({});
$("#webbodycontainer").html(window.currentSection.$el);
window.currentSection.render();
});
問:
- 我可以創建動態子路由器嗎?
- 我可以爲每個路由器創建動態視圖嗎?
- 如果可能,我該如何創建它?
謝謝,但關於它的任何樣本例子嗎? – Nothing
首先,告訴我你在做什麼'serviceTagAction'和'serviceSurveyAction'? –
我已更新我的問題。謝謝。 – Nothing