jQuery移动小部件无法在require.js / backbone框架中呈现

时间:2013-06-12 11:59:57

标签: cordova requirejs jquery-mobile-listview

使用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元素的情况下出现。

对于ref:页面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的开发。

1 个答案:

答案 0 :(得分:0)

尝试在相关页面上调用触发器(&#39;创建&#39;)进行刷新