我正在尝试设计类似于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以获取数据的世界.
有人对我有什么建议吗?
我正在开发一个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)
如何将数据传递到子视图?或者有更好的方法吗?
提前致谢!
我正在尝试对使用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) 似乎有一千人在堆栈溢出时询问相同的问题,但似乎没有单一的解决方案来解决这个问题.我要再问一次......
我有一个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) 让我们从代码开始..
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) 如何在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 ×2
knockout.js ×2
angularjs ×1
asp.net-mvc ×1
durandal ×1
events ×1
javascript ×1
sammy.js ×1
unit-testing ×1