我有以下类型的变量{Newtonsoft.Json.Linq.JArray}
.
properties["Value"] {[
{
"Name": "Username",
"Selected": true
},
{
"Name": "Password",
"Selected": true
}
]}
Run Code Online (Sandbox Code Playgroud)
我想做到的是将其转换为List<SelectableEnumItem>
那里SelectableEnumItem
是以下类型:
public class SelectableEnumItem
{
public string Name { get; set; }
public bool Selected { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我对编程很新,我不确定这是否可行.任何有关工作示例的帮助将不胜感激.
我有一个名为的角度服务requestNotificationChannel
:
app.factory("requestNotificationChannel", function($rootScope) {
var _DELETE_MESSAGE_ = "_DELETE_MESSAGE_";
function deleteMessage(id, index) {
$rootScope.$broadcast(_DELETE_MESSAGE_, { id: id, index: index });
};
return {
deleteMessage: deleteMessage
};
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用jasmine对此服务进行单元测试:
"use strict";
describe("Request Notification Channel", function() {
var requestNotificationChannel, rootScope, scope;
beforeEach(function(_requestNotificationChannel_) {
module("messageAppModule");
inject(function($injector, _requestNotificationChannel_) {
rootScope = $injector.get("$rootScope");
scope = rootScope.$new();
requestNotificationChannel = _requestNotificationChannel_;
})
spyOn(rootScope, '$broadcast');
});
it("should broadcast delete message notification", function(done) {
requestNotificationChannel.deleteMessage(1, 4);
expect(rootScope.$broadcast).toHaveBeenCalledWith("_DELETE_MESSAGE_", { id: 1, index: 4 });
done();
});
});
Run Code Online (Sandbox Code Playgroud)
我读到了Jasmine中的异步支持,但由于我对使用javascript的单元测试不熟悉,因此无法使其正常工作.
我收到一个错误: …
根据Michal Charemza的帖子编辑.
我有一个代表angularui模态对话框的服务:
app.factory("dialogFactory", function($modal, $window, $q) {
function confirmDeleteDialog() {
var modalInstance = $modal.open({
templateUrl: "../application/factories/confirmDeleteDialog.htm",
controller: function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close("true");
};
$scope.cancel = function() {
$modalInstance.dismiss("false");
};
}
});
return modalInstance.result.then(function(response) {
return 'My other success result';
}, function(response) {
return $q.reject('My other failure reason');
});
};
return {
confirmDeleteDialog: confirmDeleteDialog
};
});
Run Code Online (Sandbox Code Playgroud)
如果用户从对话框中单击"确定",则调用delete方法requestNotificationChannel.deleteMessage(id)
.
$scope.deleteMessage = function(id) {
var result = dialogFactory.confirmDeleteDialog();
result.then(function(response) {
requestNotificationChannel.deleteMessage(id);
});
};
Run Code Online (Sandbox Code Playgroud)
问题是我无法对此进行单元测试.
这是我的考验.我已经正确地注入了q服务,但我不确定我应该从"confirmDeleteDialog"
间谍返回什么...
describe("has …
Run Code Online (Sandbox Code Playgroud) 我有一个带有隔离范围的指令,其值为双向绑定到父范围.我正在调用一个方法来更改父作用域中的值,但是我的指令中没有应用更改.(不会触发双向绑定).这个问题非常相似:
AngularJS:父范围未在指令(具有隔离范围)双向绑定中更新
但我没有更改指令中的值,只是在父作用域中更改它.我读了解决方案,在第五点说:
The watch() created by the isolated scope checks whether it's value for the bi-directional binding is in sync with the parent's value. If it isn't the parent's value is copied to the isolated scope.
Run Code Online (Sandbox Code Playgroud)
这意味着当我的父值更改为2时,将触发监视.它检查父值和指令值是否相同 - 如果不相同,则复制到指令值.好的,但我的指示值仍然是1 ...我错过了什么?
HTML:
<div data-ng-app="testApp">
<div data-ng-controller="testCtrl">
<strong>{{myValue}}</strong>
<span data-test-directive data-parent-item="myValue"
data-parent-update="update()"></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
var testApp = angular.module('testApp', []);
testApp.directive('testDirective', function ($timeout) {
return {
scope: {
key: '=parentItem',
parentUpdate: '&'
},
replace: true,
template:
'<button data-ng-click="lock()">Lock</button>' +
'</div>',
controller: …
Run Code Online (Sandbox Code Playgroud) 我有一个包含在指令中的angularUi模态窗口:
HTML:
<!doctype html>
<html ng-app="plunker">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script>
<script src="main.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div my-modal="{ data: 'test2'}">test2</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
angular.module('plunker', ['ui.bootstrap', 'myModal']);
angular.module("myModal", []).directive("myModal", function ($modal) {
"use strict";
return {
template: '<div ng-click="clickMe(rowData)" ng-transclude></div>',
replace: true,
transclude: true,
scope: {
rowData: '&myModal'
},
link: function (scope, element, attrs) {
scope.clickMe = function () {
$modal.open({
template: "<div>Created By:" + scope.rowData().data + "</div>"
+ "<div class=\"modal-footer\">"
+ "<button class=\"btn btn-primary\" ng-click=\"ok()\">OK</button>"
+ "<button class=\"btn …
Run Code Online (Sandbox Code Playgroud) 我正在使用Asp.net MVC3和knockoutjs库.我需要做一些客户端验证.我正在探索淘汰赛验证插件.
所以我在我的js代码中声明了以下ko.observable值:
var numberValue = ko.observable().extend({ number: true })
Run Code Online (Sandbox Code Playgroud)
这是我的观点部分:
<input data-bind = "value: numberValue " />
Run Code Online (Sandbox Code Playgroud)
当用户输入一些不是数字的值时,会显示错误消息:"请输入一个数字".我可以显示不同的错误消息但仍使用本机规则吗?我不想为此编写自定义验证逻辑.任何有关工作示例的帮助将不胜感激.谢谢!
我有以下html:
<div data-bind="stopBindings">
<div data-viewId="languageList" data-bind="with: viewModel">
<table>
<tr>
<td ><label for="availableLanguages">Available Languages:</label></td>
</tr>
<table>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想制作一个自定义的html助手并像这样使用它(类似于Html.BeginForm
)
@Html.BeginView()
{
<table>
<tr>
<td ><label for="availableLanguages">Available Languages:</label></td>
</tr>
</table>
}
Run Code Online (Sandbox Code Playgroud)
我开始制作我的助手方法
public static class BeginViewHelper
{
public static MvcHtmlString BeginView(this HtmlHelper helper, string viewId)
{
var parentDiv = new TagBuilder("div");
parentDiv.MergeAttribute("data-bind", "preventBinding: true");
return new MvcHtmlString();
}
}
Run Code Online (Sandbox Code Playgroud)
我读了如何制作基本的html助手,但我看到的例子并没有给我提供如何在我的情况下制作它的信息.我对asp mvc很新,每一个帮助都将不胜感激.
更新2:
显然我错过了一些东西.我在我的观点中称之为:
@Html.BeginView()
{
<table>
<tr>
<td ><label >test</label></td>
</tr>
</table>
}
Run Code Online (Sandbox Code Playgroud)
一切看起来都很好,甚至还有智能感知.但浏览器中的输出如下:
Omega.UI.WebMvc.Helpers.BeginViewHelper+MyView {
test
}
Run Code Online (Sandbox Code Playgroud)
这是我的助手方法:
namespace …
Run Code Online (Sandbox Code Playgroud) 我有以下HTML代码.单击标签时,它会切换复选框.
<td><label for="startClientFromWebEnabled">Client Launch From Web:</label></td>
<td><input type="checkbox" id="startClientFromWebEnabled" name="startClientFromWebEnabled" data-bind="checked: StartClientFromWebEnabled, enable: IsEditable" onchange="startClientFromWebToggleRequiredAttribute()" /></td>
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止这个?如果我删除它for="startClientFromWebEnabled"
,它停止切换但我需要这个因为我有一些逻辑,从触发事件的元素中获取id ...
我有一个对象数组.数组中的每个对象都有一个id和一个item属性,它是一个包含其他对象的数组.我需要能够通过id在数组中找到一个元素.这是我到目前为止所做的一个示例,但递归函数总是返回undefined.
当我多次递归调用函数时,如何退出函数并返回项目?
$(function () {
var treeDataSource = [{
id: 1,
Name: "Test1",
items: [{
id: 2,
Name: "Test2",
items: [{
id: 3,
Name: "Test3"
}]
}]
}];
var getSubMenuItem = function (subMenuItems, id) {
if (subMenuItems && subMenuItems.length > 0) {
for (var i = 0; i < subMenuItems.length; i++) {
var item;
if (subMenuItems[i].Id == id) {
item = subMenuItems[i];
return item;
};
getSubMenuItem(subMenuItems[i].items, id);
};
};
};
var searchedItem = getSubMenuItem(treeDataSource, 3);
alert(searchedItem.id);
});
Run Code Online (Sandbox Code Playgroud)
angularjs ×5
c# ×2
jasmine ×2
javascript ×2
algorithm ×1
asynchronous ×1
debugging ×1
html ×1
jquery ×1
jquery-ui ×1
json.net ×1
knockout.js ×1
modal-dialog ×1
promise ×1
unit-testing ×1