I am trying to create a MVC structure of an application in canjs. For this, I use requireJS to split the code in another file.
I searched on google and I follow this tutorial , but in this tutorail I do not find access to module variables in different modules. so I follow the this method for this.
But I canβt achieve this. This is my code:
requirejsconfig.js file:
requirejs.config({
paths :{
enforceDefine: true,
waitSeconds : 0,
jquery : "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min",
main : "view/main",
player : "view/player",
PlayerModel : "/models/PlayerModel",
hbs : "/models/view/js/handlebars",
fixture : "/models/view/js/can.fixture",
can : "/models/view/js/can.jquery"
}
});
main.js:
require(["player"],function(player){
player.PlayerModel();
});
I want to use these model methods in my controller.
player.js:
define(['PlayerModel'],function(){
function PlayerModel(){
var Player = PlayerModel.Player;
Players =can.Control({ defaults :{view:view/players.hbs' }},{
init: function(){
this.element.html(can.view(this.options.view, {
players: this.options.players
}));
}
$(document).ready(function(){
$.when(Player.findAll()).then(
function(playersResponse){
var players = playersResponse[0];
new Players('.players', {
players: players
});
});
});
}
});
PlayerModel.js:
define(function(){
var Player = can.Model({
findAll: 'GET /models/players.json',
findOne: 'GET /players.json/{id}'
});
return {
Player:Player
}
});
Each file is loaded (displayed in the network tab-chrome devtools), but nothing is filled in the output.
Can someone help me? Thanks in advance!