2016-03-05 8 views
4

У меня есть следующие основные:Требовать, Нокаут и пейджинговой являются Неопределенное TypeError

requirejs.config({ 
    paths:{ 
    'text':'../vendor/js/text.min', 

    'jquery':"../vendor/js/jquery.min", 
    'boostrap':"../vendor/js/bootstrap.min", 
    'ko':"http://knockoutjs.com/downloads/knockout-3.4.0.debug", 
    'pager':"../vendor/js/pager", 

    'imageGroupsVm':'../js/viewModels/imageGroupsViewModel', 
    'panelVm':'../js/viewModels/panelViewModel', 

    'compMessage':'../js/components/message', 
    'extBooleanToggle':'../js/extenders/booleanToggle' 
    }, 
    shim:{ 
    'bootstrap':['jquery'], 
    'pager':['ko'], 
    }, 
    waitSeconds: 200, 
}); 

define(['jquery','ko','pager','panelVm'],function($,ko,pager,panelVm) 
{ 
    pager.extendWithPage(panelVm); 
    ko.applyBindings(panelVm); 
    pager.start(); 
}); 

Но по какой-то причине я получаю эти сообщения об ошибках 2:

TypeError: ko is undefined 
Stack trace: 
[email protected]://localhost/symphotest/assets/vendor/js/pager.js:150:9 
@http://localhost/symphotest/assets/vendor/js/pager.js:1506:20 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1690:24 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:865:43 
newContext/Module.prototype.enable/</<@http://localhost/symphotest/assets/vendor/js/require.min.js:1140:29 
bind/<@http://localhost/symphotest/assets/vendor/js/require.min.js:131:20 
newContext/Module.prototype.emit/<@http://localhost/symphotest/assets/vendor/js/require.min.js:1190:21 
[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:56:31 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1189:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:940:25 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1177:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:783:21 
callG[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1204:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1604:1 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1711:21 
require.min.js:900:37 

TypeError: pager is undefined 
Stack trace: 
@http://localhost/symphotest/assets/js/panel-main.js:65:5 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1690:24 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:865:43 
newContext/Module.prototype.enable/</<@http://localhost/symphotest/assets/vendor/js/require.min.js:1140:29 
bind/<@http://localhost/symphotest/assets/vendor/js/require.min.js:131:20 
newContext/Module.prototype.emit/<@http://localhost/symphotest/assets/vendor/js/require.min.js:1190:21 
[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:56:31 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1189:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:940:25 
newContext/Module.prototype.enable/</<@http://localhost/symphotest/assets/vendor/js/require.min.js:1140:29 
bind/<@http://localhost/symphotest/assets/vendor/js/require.min.js:131:20 
newContext/Module.prototype.emit/<@http://localhost/symphotest/assets/vendor/js/require.min.js:1190:21 
[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:56:31 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1189:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:940:25 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1177:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:783:21 
[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1204:17 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1604:1 
newContext/[email protected]://localhost/symphotest/assets/vendor/js/require.min.js:1711:21 
require.min.js:900:37 

Furtermore panelViewModel.js содержит:

define(['ko','imageGroupsVm','compMessage'],function(ko,ImageGroupsVM,loginViewModel) 
{ 
    var image_groups=new ImageGroupsVM(); 


    return {'imageGroups':image_groups}; 
}); 

И ImageGroupsViewModel Содержит:

define(['ko','jquery'],function(ko,$) 
{ 
    console.log(ko); 
    return function imageGroupsViewModel() 
    { 
    var self=this; 

    self.albums=ko.observableArray(); 

    self.init=function() 
    { 
     self.albums([]); 

     self.fetchData(); 
    } 

    self.fetchData=function() 
    { 
     console.log("Data Fetched"); 
    }; 

    function Album(data) 
    { 

    } 
    }; 
}) 

всех JS файлы, которые я являются: (Обратите внимание, что классы олова поставщика являются внешние библиотеки I нагрузки)

Js Files

Пожалуйста, вы можете мне помочь, чтобы выяснить эту проблему?

ответ

2

Мне удалось исправить это, заменив «ko» на «нокаут», когда это требуется.

Более конкретно на основном (файл, который включает в данной магистрали на вашем HTML)

Следующая строка:

'ko':"http://knockoutjs.com/downloads/knockout-3.4.0.debug", 

Изменена в:

'knockout':"http://knockoutjs.com/downloads/knockout-3.4.0.debug", 

Я включил на регулировочной шайбе :

'pager':['knockout'], 

И

define(['jquery','ko','pager','panelVm'],function($,ko,pager,panelVm) 

Изменено в

define(['jquery','knockout','pager','panelVm'],function($,ko,pager,panelVm) 

Поэтому мой основной является:

requirejs.config({ 
    paths:{ 
    'text':'../vendor/js/text.min', 

    'knockout':"https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min", 
    'pager':"../vendor/js/pager.min", 
    'jquery':"../vendor/js/jquery.min", 
    'boostrap':"../vendor/js/bootstrap.min", 

    'imageGroupsVm':'../js/viewModels/imageGroupsViewModel', 
    'panelVm':'../js/viewModels/panelViewModel', 

    'compMessage':'../js/components/message', 
    'extBooleanToggle':'../js/extenders/booleanToggle' 
    }, 
    shim:{ 
    'pager':['knockout'], 
    'bootstrap':['jquery'], 
    }, 
    waitSeconds: 200, 
}); 

define(['jquery','knockout','pager','panelVm'],function($,ko,pager,panelVm) 
{ 
    pager.extendWithPage(panelVm); 
    ko.applyBindings(panelVm); 
    pager.start(); 
}); 

Кроме того, на других моих файлов JavaScript на моем проекте, которые загружаются с требуют я изменил строку:

define(['ko',...,'other_lib'],function(ko,....,other_lib) 

С:

define(['knockout',...,'other_lib'],function(ko,....,other_lib) 

Примечание: Я также изменил theese линии на других main.js, что я загружаю с требуется на других страницах:

'ko':"http://knockoutjs.com/downloads/knockout-3.4.0.debug", 

Изменено в:

'knockout':"http://knockoutjs.com/downloads/knockout-3.4.0.debug", 

I сделал это, чтобы загрузить все модули, которые я делаю, используя require.