我的页面中有userdata
render('page',{userdata: data})
使用userdata
。
{
usename: "jim",
latLng: {lat: 10, lng: -8},
address: {
line1: "10 Main Street"
line2: "London"
country: "Great Britan"
},
about: "I am jim"
}
是具有属性的对象:
page.ejs
在我的<% console.log("My User data: " + userdata) %>
<% console.log("The latLng field: " + userdata.latLng) %>
文件中,我有以下两行代码作为测试。
My user data: {usename: 'jim',
latLng: {lat: 10, lng: -8},
address: {
line1: "10 Main Street"
line2: "London"
country: "Great Britan"
},
about: 'I am jim'}
第一个显示到控制台:
The latLng field: undefined
但第二行显示:
typeof userdata
有谁知道发生了什么?是因为它们是数字而不是字符串? latLng是保留变量名吗?我对于为什么会发生这种情况一无所知。
我尝试了什么:
将lat和lng保存为字符串。 (没效果)
进一步的信息:
object
在呈现过程中返回typeof data
。
object
也会返回//Names that correspond to 5 values in table1 and 5 in tab
$names = array(
'aatrox', 'ahri', 'akali', 'alistar', 'amumu', 'anivia', 'annie',
'ashe', 'azir', 'bard', 'blitzcrank', 'brand', 'braum', 'caitlyn',
'cassiopeia', 'chogath', 'corki', 'darius', 'diana', 'drmundo',
'draven', 'ekko', 'elise', 'evelynn', 'ezreal', 'fiddlesticks', 'fiora',
'fizz', 'galio', 'gangplank', 'garen', 'gnar', 'gragas', 'graves',
'hecarim', 'heimerdinger', 'irelia', 'janna', 'jarvaniv', 'jax',
'jayce', 'jinx', 'kalista', 'karma', 'karthus', 'kassadin', 'katarina',
'kayle', 'kennen', 'khazix', 'kogmaw', 'leblanc', 'leesin', 'leona',
'lissandra', 'lucian', 'lulu', 'lux', 'malphite', 'malzahar', 'maokai',
'masteryi', 'missfortune', 'mordekaiser', 'morgana', 'nami', 'nasus',
'nautilus', 'nidalee', 'nocturne', 'nunu', 'olaf', 'orianna',
'pantheon', 'poppy', 'quinn', 'rammus', 'reksai', 'renekton', 'rengar',
'riven', 'rumble', 'ryze', 'sejuani', 'shaco', 'shen', 'shyvana',
'singed', 'sion', 'sivir', 'skarner', 'sona', 'soraka', 'swain',
'syndra', 'tahmkench', 'talon', 'taric', 'teemo', 'thresh', 'tristana',
'trundle', 'tryndamere', 'twistedfate', 'twitch', 'udyr', 'urgot',
'varus', 'vayne', 'veigar', 'velkoz', 'vi', 'viktor', 'vladimir',
'volibear', 'warwick', 'wukong', 'xerath', 'xinzhao', 'yasuo', 'yorick',
'zac', 'zed', 'ziggs', 'zilean', 'zyra'
);
//Array for table1
$table1 = array();
//Array for table2
$table2 = array();
$numNames = count($names);
//Selecting 5 values (topratio, jungleratio, midratio, adcratio, supportratio) from table1 and corresponding them to their name.
for($i = 0; $i < $numNames; $i++){
$query = $dbconn->query("SELECT topratio, jungleratio, midratio,
adcratio, supportratio
FROM table1
WHERE name = '".$names[$i]."'
ORDER BY Id DESC LIMIT 1");
$table1[$names[$i]] = $query->fetch_assoc();
};
//Selecting 5 values (topdiapr, junglediapr, middiapr, adcdiapr, supportdiapr) from table2 and corresponding them to their name.
for($i = 0; $i < $numNames; $i++){
$query = $dbconn->query("SELECT topdiapr, junglediapr, middiapr,
adcdiapr, supportdiapr
FROM table2
WHERE name = '".$names[$i]."'
ORDER BY Id DESC LIMIT 1");
$table2[$names[$i]] = $query->fetch_assoc();
};
。