删除函数Javascript、knockout、c、asp.net
嗨,我想创造一些类似于计划扑克的东西。目前我有它,所以你可以创建一个游戏,我正试图使它,所以你可以删除一个游戏。当前“我的删除”会删除游戏,但只有在点击“刷新”时才会暂时删除它们。我知道我必须做什么,只是不知道怎么做。我需要删除按钮从我的控制器中的可观察阵列中删除游戏 这是我的密码 索引创建游戏删除函数Javascript、knockout、c、asp.net,javascript,asp.net,knockout.js,Javascript,Asp.net,Knockout.js,嗨,我想创造一些类似于计划扑克的东西。目前我有它,所以你可以创建一个游戏,我正试图使它,所以你可以删除一个游戏。当前“我的删除”会删除游戏,但只有在点击“刷新”时才会暂时删除它们。我知道我必须做什么,只是不知道怎么做。我需要删除按钮从我的控制器中的可观察阵列中删除游戏 这是我的密码 索引创建游戏 <html> <head> <title>Planning Poker</title> <style> .inlinetext {
<html>
<head>
<title>Planning Poker</title>
<style>
.inlinetext {
display: inline;
}
</style>
<script src="Scripts/jquery-2.1.1.js"></script>
<script src="Scripts/knockout-3.1.0.js"></script>
<script type="text/javascript">
$(function () {
$('#button').on('click', function (data) {
$.post('data/games/create/?title=5', function (d) { console.log(d) });
})
});
</script>
</head>
<body>
<h3 class='inlinetext'> Create Game: </h3>
<input type="text" id="testtext" name="ime">
<button id="button" >Create</button>
</body>
</html>
控制器
using PlanningPoker.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace PlanningPoker.Controllers
{
public class GMController : ApiController
{
private static List<Game> games = new List<Game>() {
new Game() {
ID = Guid.NewGuid(),
Title = "D&D"
}
};
[Route("data/games")]
public IEnumerable<Game> GetAllGames() {
return games;
}
[Route("data/games/create"), HttpPost]
public Guid CreateGame(string title) {
Game g = new Game() {
ID = Guid.NewGuid(),
Title = title
};
games.Add(g);
return g.ID;
}
}
击倒教程的第4步准确地演示了您想要实现的目标
self.removeGames = function(game) { self.games.remove(game) }
看看你的self.removeGames函数:这个函数的范围是什么?我建议使用敲除本身传递的实际项目。self.removeGames=functionitem{self.games.removietem;}您还需要执行一个ajax请求,以便从服务器的removeGames函数中删除该项
using PlanningPoker.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace PlanningPoker.Controllers
{
public class GMController : ApiController
{
private static List<Game> games = new List<Game>() {
new Game() {
ID = Guid.NewGuid(),
Title = "D&D"
}
};
[Route("data/games")]
public IEnumerable<Game> GetAllGames() {
return games;
}
[Route("data/games/create"), HttpPost]
public Guid CreateGame(string title) {
Game g = new Game() {
ID = Guid.NewGuid(),
Title = title
};
games.Add(g);
return g.ID;
}
}
self.removeGames = function(game) { self.games.remove(game) }