我有一个关于使用的问题new[].
想象一下:
Object.SomeProperty = new[] {"string1", "string2"};
Run Code Online (Sandbox Code Playgroud)
SomeProperty需要一个字符串数组.
我知道这段代码会起作用.但我想知道它在幕后做了什么.是否new[]创建了类的实例,object并在SomeProperty其中将其自动转换为string对象?
谢谢
我的所有指令都使用相同的范围,我希望我的指令可以自己操作.
指示:
app.directive('headerSort', function () {
return {
restrict: 'A',
controller: function ($scope, $element, $attrs) {
$scope.caption = $attrs.caption;
$scope.doSort = function () {
$scope.orderField = $attrs.headerSort;
$scope.reverse = !$scope.reverse;
};
},
template: '<div data-ng-click="doSort();">' +
'{{caption}}' +
'<i class="icon-sort"></i>' +
'</div>'
};
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<th data-header-Sort="FullName" data-caption="Full name"></th>
<th data-header-Sort="FirsName" data-caption="First name"></th>
<th data-header-Sort="Age" data-caption="Age"></th>
Run Code Online (Sandbox Code Playgroud)
结果是所有列都具有值'Age'并按Age排序.我当然希望每列都对它自己的列进行排序.我怎样才能做到这一点?
更新:忘了提及,orderField并reverse用于ng-repeat | orderBy:
<tbody id="customerRows" data-ng-repeat="customer in customers | orderBy:orderField:reverse">
Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的jsfiddle来说明我的问题:
HTML:
<div ng-controller="MyCtrl">
<div ng-repeat="p in products">
<span ng-click="overwrite(p)">{{ p.id }}: {{ p.name }}</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
var products = [{id:1, name:'first'}, {id:2, name:'second'}];
$scope.products = products;
var prod = {id: 3, name:'third'};
$scope.overwrite = function(p){
p.id = 4;
p.name = 'forth';
p = prod; // this doesn't work nor does angular.copy(prod)
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,当我手动设置属性时,值是bind.但是当我覆盖一个对象时,没有任何反应.这怎么可能?当我想要恢复其原始状态的对象时,我该怎么办?
想象一下,我使用创建备份对象var productBackup = angular.copy(product).然后我对原始产品进行了更改,之后我决定取消更改.我想用这个来做product = productBackup.但这不起作用!在这种情况下,我是否需要像这样手动设置所有属性?
product.id = productBackup.id;
product.name = productBackup.name; …Run Code Online (Sandbox Code Playgroud) 我将Angular与MVC结合使用.当我想上传文件时,HttpPostedFileBase为空.
HTML:
<input type="file" data-ng-model="fileName" onchange="angular.element(this).scope().fileInputChanged(this)">
Run Code Online (Sandbox Code Playgroud)
角度:
scope.fileInputChanged = function (element) {
scope.$apply(function (scope) {
console.log('files:', element.files);
_.each(element.files, function (element, index, list) {
scope.files.push(element);
});
});
}
scope.uploadDocuments = function () {
var formData = new FormData();
// add uploaded files to form data object
for(var i in scope.files){
formData.append("uploadedFile", scope.files[i]);
}
// create xml http request object
var httpRequest = new XMLHttpRequest();
httpRequest.upload.addEventListener("progress", uploadProgress, false);
httpRequest.addEventListener("load", uploadComplete, false);
httpRequest.addEventListener("error", uploadFailed, false);
httpRequest.addEventListener("abort", uploadCanceled, false);
httpRequest.open("POST", "/Customer/UploadDocuments");
// …Run Code Online (Sandbox Code Playgroud) 与此问题类似: C#Constructor Design但这个问题略有不同.
我有一个Customer类和一个CustomerManager类.当创建CustomerManager类的实例时,我想加载所有客户.这就是我陷入困境的地方.我可以通过以下几种方式做到:
在执行数据库相关操作的CustomerManager类的每个方法中,检查加载的本地客户列表,如果没有,请加载列表:
public method FindCustomer(int id)
{
if(_customers == null)
// some code which will load the customers list
}
Run Code Online (Sandbox Code Playgroud)创建一个加载所有客户的方法.必须在调用执行数据库相关操作的方法之前调用此方法:
在课堂里:
public LoadData()
{
// some code which will load the customers list
}
Run Code Online (Sandbox Code Playgroud)
形式如下:
CustomerManager manager = new CustomerManager();
manager.LoadData();
Customer customer = manager.FindCustomer(int id);
Run Code Online (Sandbox Code Playgroud)做这个的最好方式是什么?
编辑:
我觉得我在这里被误解了.也许是因为我不够清楚.在CustomerManager类中,我有几种方法取决于本地列表(_customers).所以,我的问题是,我应该在哪里填写该清单?
我想在字符串中执行不区分重音的替换.我希望'客户'匹配'cliënt',反之亦然.
我的代码看起来像这样:
Regex reg = new Regex("client");
string result = reg.Replace("here goes the content with client and cliënt", "replacementWith");
Run Code Online (Sandbox Code Playgroud)
那么,我如何确保'客户'匹配'客户'和'cliënt',反之亦然?
我想创建(或下载,但我找不到任何)时间轴控件.我的想法是这样的:

在这张图片中,我只对时间表感兴趣,左边的资源和水平的时间.
有谁能告诉我开发这种控制的好方法是什么?我已经尝试了tablelayout控件,但我现在卡住了,因为我无法计划需要2分钟的事情.由于性能的原因,我也不想为每一分钟绘制一个列,它看起来太忙了.
我做了一个自定义控件,当条件满足时,我想显示一个工具提示:
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
var plannedItem = GetPlannedItemByPosition(e.Location);
if (plannedItem != null)
_tooltip.SetToolTip(this, plannedItem.Description);
else
_tooltip.RemoveAll();
}
Run Code Online (Sandbox Code Playgroud)
此代码工作正常,除了工具提示闪烁的面孔.
这个自定义控件,描绘了OnPaint事件中的所有信息,也许这与它有关?如果是这样,我怎样才能防止工具提示闪烁?
我想知道存储哪种文件
C:\ Program Files(x86)\ Reference Assemblies\Microsoft\Framework.NETFramework\v4.0 \
这些文件是否适用于WPF/Silverlight?
哪个安装程序将文件安装在该文件夹中?
我想知道这一点,因为我们开发了一个带有自定义WPF控件的winforms应用程序.当我们在裸系统上部署应用程序时,应用程序在使用这些控件时崩溃...
我写了这样一个指令:
app.directive('headersort', function () {
return {
restrict: 'E',
scope: {
sortBy: '=',
title: '='
},
template: '<th>{{ title }}</th>',
replace: true,
link: function (scope, element, attributes) {
scope.sortBy = attributes.sortBy;
scope.title = attributes.title;
}
};
});
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
<headersort sortBy="Name" title="Product">
Run Code Online (Sandbox Code Playgroud)
我想要的是<headersort sortBy="Name" title="Product">被替换为<th>Product</th>.但我得到一个错误说:
Template must have exactly one root element. was: <th>{{ title }}</th>
但我确实有一个根元素,对吗?我的根元素是<th>,为什么角度抛出这个错误?根元素的条件/定义是什么?
c# ×7
angularjs ×4
winforms ×4
javascript ×3
.net-4.0 ×1
asp.net-mvc ×1
assemblies ×1
new-operator ×1
regex ×1