我的代码中出现意外标记 )
Unexpected token ) in my code
我正在学习 canjs 并尝试检索数据。由于我是初学者,所以我将整个代码写在一个文件中。
这是我的 canjs 文件:
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
});
});
});
这是我的 ejs 模板:
<ul id="sidebar">
<% list(players, function(player){ %>
<li class="player" <%=(el)-> el.data('player', player) %>>
<%== can.view.render('playerView.ejs', {
player:player
})
%>
</li>
<% }) %>
虽然 运行 文件显示错误 Uncaught SyntaxError: Unexpected token ) in jquery.
但这怎么可能呢?我没有更改 jquery.
中的任何内容
你一定是漏掉了什么
$(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
});
});
});
更新:尝试在playersResponse[0]末尾添加一个分号(;)。希望这对你有所帮助。
我正在学习 canjs 并尝试检索数据。由于我是初学者,所以我将整个代码写在一个文件中。
这是我的 canjs 文件:
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
});
});
});
这是我的 ejs 模板:
<ul id="sidebar">
<% list(players, function(player){ %>
<li class="player" <%=(el)-> el.data('player', player) %>>
<%== can.view.render('playerView.ejs', {
player:player
})
%>
</li>
<% }) %>
虽然 运行 文件显示错误 Uncaught SyntaxError: Unexpected token ) in jquery.
但这怎么可能呢?我没有更改 jquery.
中的任何内容你一定是漏掉了什么
$(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
});
});
});
更新:尝试在playersResponse[0]末尾添加一个分号(;)。希望这对你有所帮助。