小编mco*_*ham的帖子

通知系统的数据库模式与Facebook类似

我正在尝试设计类似于facebook的通知系统,我已经达到了一点砖墙.我的要求是能够支持无数种通知类型,这些通知类型可能需要呈现不同类型的元数据.

我想我会按如下方式设计架构:

**Notification**
Id (int)
TypeId (int)
RecipientId (int)
SenderId (int)
SendDateTime (DateTime)
Read (bool)
MessageData (...Blob?)
Deleted (bool)

**NotificationType**
Id
Name
Description
Run Code Online (Sandbox Code Playgroud)

我真的想避免在我的数据库中存储HTML字符串,但是,我也不是特别喜欢存储blob.

我可以查看NotificationType表并引用另一个存储特定于该类型的数据的表,但是,这意味着每次创建新的notificationtype时我都需要创建一个新表.我相信我也会进入一个不得不编写动态SQL以获取数据的世界.

有人对我有什么建议吗?

notifications database-design

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

Durandal多主页

我正在开发一个SPA,我想使用多个主视图.这是我的用例:

我有一个有个人资料页面的用户.在该个人资料页面中,我希望能够显示几个不同的视图,即.细节,作品,联系信息等.我需要能够深入链接到每个视图.这些视图中的每一个都必须显示主布局视图中的基本用户数据.

我的理解是我应该使用compose这个并且我有一些似乎有用的代码,但是,我希望能够将数据从"辅助shell"传递到实际的子视图.似乎splat数据不会传递给子视图模型的activate方法.

在我的"master"viewmodel中,我创建了一个名为activeView的observable,它包含一个对应于子视图模型的字符串(viewmodels/user/details).然后,我有一个敲门声明如下:

<!-- ko compose: {
    model: activeView(),        
    activate: true
} --><!-- /ko -->
Run Code Online (Sandbox Code Playgroud)

如何将数据传递到子视图?或者有更好的方法吗?

提前致谢!

sammy.js knockout.js single-page-application durandal

8
推荐指数
1
解决办法
2762
查看次数

使用ngModel的单元测试角度指令

我正在尝试对使用ngModel并遇到困难的指令进行单元测试.似乎我的指令的链接功能永远不会被调用...

这是我的指令代码:

coreModule.directive('coreUnit', ['$timeout', function ($timeout) {
    return {
        restrict: 'E',
        require: '?ngModel',
        template: "{{output}}",
        link: function (scope, elem, attrs, ngModelCtrl) {
            ngModelCtrl.$render = function () {
                render(ngModelCtrl.$modelValue);
            };
            console.log("called");
            function render(unit) {
                if (unit) {
                    var output = '(' +
                        unit.numerator +
                        (unit.denominator == '' ? '' : '/') +
                        unit.denominator +
                        (unit.rate == 'NONE' || unit.rate == '' ? '' : '/' + unit.rate) +
                        ')';
                    scope.output = output == '()' ? '' : output;
                }
            }
        } …
Run Code Online (Sandbox Code Playgroud)

unit-testing angularjs angularjs-directive karma-jasmine

6
推荐指数
1
解决办法
5344
查看次数

存在多个获取操作时的MVC API路由

似乎有一千人在堆栈溢出时询问相同的问题,但似乎没有单一的解决方案来解决这个问题.我要再问一次......

我有一个API控制器,它具有以下操作:

    // GET api/Exploitation
    public HttpResponseMessage Get() {
        var items = _exploitationRepository.FindAll();

        var mappedItems = Mapper.Map<IEnumerable<Exploitation>, IEnumerable<ExploitationView>>(items);

        var response = Request.CreateResponse<IEnumerable<ExploitationView>>(HttpStatusCode.OK, mappedItems);
        response.Headers.Location = new Uri(Url.Link("DefaultApi", new { }));
        return response;
    }

    // GET api/Exploitation/5        
    [HttpGet, ActionName("Get")]
    public HttpResponseMessage Get(int id) {
        var item = _exploitationRepository.FindById(id);
        var mappedItem = Mapper.Map<Exploitation, ExploitationView>(item);

        var response = Request.CreateResponse<ExploitationView>(HttpStatusCode.OK, mappedItem);
        response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = id }));
        return response;
    }

    // GET api/Exploitation/GetBySongwriterId/5
    [HttpGet, ActionName("GetBySongwriterId")]
    public HttpResponseMessage GetBySongwriterId(int id) { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-routing asp.net-web-api-routing

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

淘汰复杂数据模型绑定

让我们从代码开始..

Javascript绑定viewmodel和显示对话框

$("#add-song").click(function () {
    $("<div>")
        .attr("data-bind", "template: { name: 'manage-song-template' }")
        .dialog({
            resizable: false,
            modal: true,
            title: "Add Song",
            width: 960,
            height: 490,
            buttons: [
                {
                    text: "Create Song",
                    'data-bind': 'click: savechanges',
                    click: function () {

                    }
                },
                {
                    text: "Close",
                    click: function () {
                        $(this).dialog("close");
                    }
                }
            ],
            close: function () {
                $(this).dialog('destroy').remove();
            },
            open: function () {
                ko.applyBindings(new my.managesongviewmodel());
                jquerybindings();
            }
        });        
});
Run Code Online (Sandbox Code Playgroud)

现在让我们来看看视图模型

my.managesongviewmodel = function () {
    var
        //Scalar Properties
        song = null,

        //Functions
        loadfromserver …
Run Code Online (Sandbox Code Playgroud)

javascript jquery knockout.js

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

从JQuery中的element获取click处理程序

如何在JQuery中获得对元素的单击处理程序的引用?

这是我想要做的:

存储单击处理程序,更改下一次单击的单击处理程序,还原原始单击处理程序

var originalClick = $(settings.currentTarget).click;
$(settings.currentTarget).off("click");

$(settings.currentTarget).click(function (e) {
    e.preventDefault();
    settings.model.modal.close();

    $(settings.currentTarget).off("click");
    $(settings.currentTarget).click(originalClick);
});
Run Code Online (Sandbox Code Playgroud)

上面的代码第一次工作,但是,当我再次点击该元素时,它失败了:

 Uncaught TypeError: Object [object HTMLAnchorElement] has no method 'on' 
Run Code Online (Sandbox Code Playgroud)

更新:
我现在意识到这是一个非常糟糕的设计,我正在尝试做.我已经通过在viewmodel中维护可见性布尔值来解决了这个问题,如果是,则不要重新打开模态.

jquery events event-handling

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