songjun
2024-09-04 cc908053e0b5075fbfd27350b6da4b39bca9e550
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
@model sbcLabSystem.Models.Backstage.MenusViewModel
@{
    ViewBag.Title = "公告管理";
    Layout = "~/Views/Shared/Master.cshtml";
}
 
<script>
    var viewModel;
    $(function () {
        viewModel = new myViewModel_Menus(@Html.Raw(Json.Encode(Model)));
        ko.applyBindings(viewModel, $(".container")[0]);
    })
    function myViewModel_Menus(data)
    {
        var self = this;
        self.seve = function () {
            window.location.href = "@Url.Action("Noticeinfo", "Backstage")" ;
        }
        ko.mapping.fromJS(data, mapping, self)
    }
    var mapping = {
        'MenusList': {
            create: function (options) {
                return new MenusList(options.data);
            }
        }
    }
    function MenusList(data) {
        console.log(data)
        var self = this;
        self.dateTime = ko.computed(function () {
            return formatDateTime(self.Time());
        }, self)
        self.Detailed = function () {
 
            window.location.href = "@Url.Action("Noticeinfo", "Backstage")" + "?MenuId=" + self.Id();
        }
        self.delete2 = function ()
        {
            if (confirm("你确定要删除它"))
            { $.ajax({
                type: "post",
                url: '@Url.Action("DeletenNotice", "Backstage")'+'?Id='+self.Id(),
                dataType: 'json',
                cache: false,
                contentType: 'application/json; charset=utf-8',
                data: "",
                success: function (data) {
                    window.location.href = "@Url.Action("Notices", "Backstage")";
                },
                error: function (err) {
                }
            });
              
            }
           
        }
        ko.mapping.fromJS(data, {}, self)
 
    }
</script>
<div class="container">
    
   
    <div class="row"> 
        <div class="col-xs-12">
           
            <table class="table table-bordered">
                <caption >
                    <button type="button" class="btn btn-default"
                            data-bind="click:seve">
                        <span class="glyphicon glyphicon-plus"></span>添加公告
                    </button>
                </caption>
                <thead>
                    <tr>
                        <th style="text-align:center">标题</th>
                        <th style="text-align:center">创建时间</th>
                        <th style="text-align:center">编辑</th>
 
                    </tr>
                </thead>
                <tbody data-bind="foreach:MenusList">
                    <tr>
                        <td style="text-align:center" data-bind="text:Name"></td>
                        <td style="text-align:center" data-bind="text:dateTime"></td>
                        <td style="text-align:center">
                            <span>
                                <button type="button" class="btn btn-info  btn-xs" data-bind="click:Detailed">
                                    查看
                                </button>
                                <button type="button" class="btn btn-danger  btn-xs" data-bind="click:delete2">
                                    删除
                                </button>
                            </span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>