I am learning canjs and trying to retrive the data. As I am beginner I have wrote my whole code in one file.
This is my canjs file:
Players = can.Control({
init: function(){
this.element.html(can.view('view/players.ejs',{
players: this.options.players
}));
}
})
Player = can.Model({
findAll: 'GET /players'
},{});
var PLAYERS = [
{
"id" : 1,
"name" : "Dipesh",
"rank" : 2,
"score" : 2000,
"__v" : 0
},{
"id" : 2,
"name" : "Aakanksha",
"rank" : 3,
"score" : 3920,
"__v" : 0
}];
can.fixture('GET /players', function(){
return [PLAYERS];
});
$(document).ready(function(){
$.when(Player.findAll()).then(
function(playersResponse){
var players = playersResponse[0]
new Players('.player', {
players: players
});
});
});
This is my ejs template:
<ul id="sidebar">
<% list(players, function(player){ %>
<li class="player" <%=(el)-> el.data('player', player) %>>
<%== can.view.render('playerView.ejs', {
player:player
})
%>
</li>
<% }) %>
While running the file, it shows an error Uncaught SyntaxError: Unexpected token ) in jquery.
But how is it possible? I dont change anything in jquery.
You must be missing something over here
$(document).ready(function(){
$.when(Player.findAll()).then(
function(playersResponse){
var players = playersResponse[0];
// Try to add a semicolon (;) at the end of playersResponse[0]
//Hope this should help you
new Players('.player', {
players: players
});
});
});
Update: Try to add a semicolon (;) at the end of playersResponse[0]. Hope this should help you.