小编Bre*_*ett的帖子

Web API返回嵌套的JSON值

我正在使用由web api返回的JSON结构,但是有问题.

说,我有两张桌子,TeamsPlayers.他们加入了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)

c# sql json asp.net-web-api

4
推荐指数
1
解决办法
1万
查看次数

无法使用jquery从本地存储获取数据的当前id

我正在开发一个应用程序来离线存储数据.我的问题是当我尝试从本地存储中检索数据以进行更新/编辑时,它一直只调用第一项的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)

javascript jquery html5 json

0
推荐指数
1
解决办法
211
查看次数

标签 统计

json ×2

asp.net-web-api ×1

c# ×1

html5 ×1

javascript ×1

jquery ×1

sql ×1