使用 phonegap/requirejs/backbone 构建移动应用程序。
这是视图文件:
define(['jquery','backbone',"text!templates/summary.tpl",'handlebars','jquery.mobile'],function($,Backbone,Template,Handlebars){
//now create a backbone view
var SummaryView = Backbone.View.extend({
el: $('#mcontent'), // attaches `this.el` to an existing element.
events:{
'pageinit':'',
},
//initialize template
template:Handlebars.compile(Template),
initialize: function(){
_.bindAll(this, 'render'); // fixes loss of context for 'this' within methods
this.render();
},
render: function(){
this.fill_body();
this.footer();
$('body').show();
},
fill_body: function(){
this.$el.append(this.template());
return this;
},
footer: function(){
this.$el.append('<div data-role="footer"><h4>Footer content</h4></div>');
return this;
}
});
和requirejs主文件:
require.config({
paths:{
jquery:'vendor/jquery/jquery.min',
'jquery.mobile':'vendor/jquery.mobile-1.3.1.min',
'jquery.mobile-config':'jqm-config',
underscore:'vendor/underscore/underscore-min',
backbone:'vendor/backbone/backbone-min',
handlebars:'vendor/handlebars/handlebars',
text:'vendor/text/text',
},
shim: {
'backbone': {
//These script dependencies should be loaded before loading backbone.js
deps: ['jquery','underscore'],
//Once loaded, use the global 'Backbone' as the module value.
exports: 'Backbone'
},
'underscore': {
exports: '_'
},
'handlebars' : {
exports : "Handlebars"
},
'jquery.mobile-config': {
deps: ['jquery']
},
'jquery-mobile': {
deps:['jquery','jquery.mobile-config'],
},
},
waitSeconds: 5
});
require(['views/test'],function(TestView){
new TestView;
当视图被渲染时,我看到页面中同时存在 jquery mobile js/css 文件。但是当我渲染这个 HTML 时,它只会出现而没有渲染 jquery 移动 css 元素。
参考:页面html是:
<div id="summary_page">
<div data-role="page">
<div data-role="content" class="summary" >
<ul data-role="listview" >
<li class="ui-btn-right" id="brands"> Brands </li>
<li class="ui-btn-right" id="pprofile">Personal Profile</li>
<li class="ui-btn-right" id="snetworks">Social networks</li>
<li class="ui-btn-right" id="tos">Terms and conditions</li>
<li class="ui-btn-right" id="ppolicy">Privacy/cookies</li>
</ul>
</div>
</div>
</div>
有没有人知道为什么 jquery mobile 的 css 没有出现在页面上。我目前正在android平台上为phonegap进行开发。