我正在使用由web api返回的JSON结构,但是有问题.
说,我有两张桌子,Teams和Players.他们加入了TeamID(PK on Teams and FK on Players).
我希望我的API调用返回一些类似如下的JSON格式:
[
{
TeamId: 1,
TeamName: 'Chicago Bulls',
TeamPlayers: [
{PlayerId: 1, PlayerName: 'Pau Gasol'},
{PlayerId: 2, PlayerName: 'Derrick Rose'},
{PlayerId: 3, PlayerName: 'Joakim Noah'},
{PlayerId: 4, PlayerName: 'Jimmy Butler'},
{PlayerId: 5, PlayerName: 'Taj Gibson'}]
},
{
TeamId: 2,
TeamName: 'Cleveland Cavaliers',
TeamPlayers: [
{PlayerId: 1, PlayerName: 'Lebron James'},
{PlayerId: 2, PlayerName: 'Kyrie Irving'},
{PlayerId: 3, PlayerName: 'Anderson Varejao'},
{PlayerId: 4, PlayerName: 'Dion Waiters'},
{PlayerId: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序来离线存储数据.我的问题是当我尝试从本地存储中检索数据以进行更新/编辑时,它一直只调用第一项的id,而不是调用视图中的数据的id.
请问我做错了什么?
这是我加载员工的代码:
// load cases from localStorage
var employees;
if (localStorage.getItem('employees')) {
employees = JSON.parse(localStorage.getItem('employees'));
} else {
// If no cases, create and save them
employees = [];
// offling storing of our cases
localStorage.setItem('employees', JSON.stringify(employees));
}
// show case listing in list view page
var showEmployees = function () {
//erase existing content
$('#employee_list').html('');
//insert each employee
for (var i = 0; i<employees.length; i++) {
addEmployees(employees[i]);
}
};
Run Code Online (Sandbox Code Playgroud)
这是我将员工添加到列表视图的代码:
//add an eliment to list view
var addEmployees …Run Code Online (Sandbox Code Playgroud)