最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Phonegap + require Js - Stack Overflow

programmeradmin0浏览0评论

How can we use Phonegap with require js ? I am try to add to phonegap using the require() method. My code is given below and all .js files are in the correct location. Please help me, it is able to load phonegap via AMD , or Use Normal script method like

<script type="text/javascript" src="cordova.js"></script>

this is my require config and methods

require.config({

           baseUrl: 'js/lib',

           paths: {
           controller: '../controller/controller',
           model: '../model/model',
           view: '../view/view',
           router:'../router/router'
           },

          /* map: {
           '*': {
           'tempName': 'actualName'
           }
           },*/

           shim: {
           'backbone': {
           deps: ['underscore', 'jquery','cordova'],
           exports: 'Backbone'
           },
           'underscore': {
           exports: '_'
           }
           }
           });


 require(['jquery', 'backbone', 'router', ], function ($, Backbone, Router) {

    document.addEventListener('deviceready', function () {
        alert('hi'); // working
        navigator.notification.alert('hi'); // not working

    }, false);

});

How can we use Phonegap with require js ? I am try to add to phonegap using the require() method. My code is given below and all .js files are in the correct location. Please help me, it is able to load phonegap via AMD , or Use Normal script method like

<script type="text/javascript" src="cordova.js"></script>

this is my require config and methods

require.config({

           baseUrl: 'js/lib',

           paths: {
           controller: '../controller/controller',
           model: '../model/model',
           view: '../view/view',
           router:'../router/router'
           },

          /* map: {
           '*': {
           'tempName': 'actualName'
           }
           },*/

           shim: {
           'backbone': {
           deps: ['underscore', 'jquery','cordova'],
           exports: 'Backbone'
           },
           'underscore': {
           exports: '_'
           }
           }
           });


 require(['jquery', 'backbone', 'router', ], function ($, Backbone, Router) {

    document.addEventListener('deviceready', function () {
        alert('hi'); // working
        navigator.notification.alert('hi'); // not working

    }, false);

});
Share Improve this question edited Jun 16, 2016 at 9:41 Flummox uses codidact. 2,1896 gold badges27 silver badges49 bronze badges asked Aug 13, 2013 at 10:51 Arjun T RajArjun T Raj 3,2071 gold badge23 silver badges44 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Requirejs and Phonegap tends to not work too well together.

The best way I have found is to just include the cordova script before your require modules.

<script type="text/javascript" src="cordova-2.7.0.js"></script>
<script data-main="js/main" src="require.js"></script> 

Check the answer for this question. He gives good insight into some of the problems faced.

发布评论

评论列表(0)

  1. 暂无评论