所以,我是 Require.js 的新手,我一直在通过使用 Require.js 方法加载各种其他库来学习这个库。
我已经成功加载了 Knockout.js 对象、Chart.js 对象以及自定义 Require.js 定义的对象。
但我似乎无法使用 Require.js 加载 jwplayer。这是我收到的错误方法: Uncaught TypeError: Cannot call method 'jwplayer' of undefined
这是我的示例代码(Knockout、Chart 对象均已成功加载)
require(['jwplayer/jwplayer', 'libs/Chart', 'libs/knockout-2.1.0', 'appViewModel','helper/util'], function(jwplayer, chart, ko, appViewModel, util) {
//LOADING FROM jwplayer.js
jwplayer("player").setup({
width: '320',
height: '40',
sources: [{
file: "rtmp://127.0.0.1:1935/vod/mp3:sample_1.mp3"
},{
file: "http://127.0.0.1:1935/vod/sample_1.mp3/playlist.m3u8"
}]
});
//LOADING FROM Chart.js
var barChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
data : [28,48,40,19,96,27,100]
}
]
};
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(barChartData);
//LOADING FROM knockout-2.1.0.js
ko.applyBindings(new appViewModel());
//LOADING FROM A CUSTOM DEFINED OBJECT
util.greets();
});
那么如何使用 Require.js 加载 jwplayer.js 呢?