我有很多布尔变量如下:
Boolean A;
Boolean B;
Boolean C;
Boolean D;
Boolean E;
Boolean F;
...
Run Code Online (Sandbox Code Playgroud)
我想确保它们都是假的,或者最多只有一个是真的.
如果不使用大量的IF,有没有快速的方法呢?
我有以下代码:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script type="text/javascript">
var application = angular.module('Application');
application.controller('ImageController', function ImageController($scope, $http) {
$scope.result = "Start here ...";
$http.get('api/images').
success(function (data, status, headers, config) {
$scope.images = data;
$scope.result = "Everything is ok";
}).
error(function (data, status, headers, config) {
$scope.result = "Something went wrong";
});
});
</script>
<div ng-app="Application" ng-controller="ImageControler">
<p>{{result}}</p>
<div ng-repeat='image in images'>
<span>{{image.votes}}</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我在渲染的HTML页面上获得的是{{result}}和{{image.votes}},例如Angular无效...我还检查了API并且没有调用它...
我错过了什么?
我有以下代码将变量除以100并为其供电.
var a = 1;
var b = (a / 100) ^ 2;
Run Code Online (Sandbox Code Playgroud)
'b'中的值变为2,应该是0.01 ^ 2 = 0.0001.
这是为什么?
我有一些包含帖子内容的HTML:
<div class="post-content">
<iframe width="40" other-properties>
iframe code
</iframe>
Other content and other tags
</div>
Run Code Online (Sandbox Code Playgroud)
如何使用div包装在post-content中找到的所有iframe标记:
<div class="post-content">
<div class="video">
<iframe width="40" other-properties>
iframe code
</iframe>
Other content and other tags
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我有以下内容:
public Boolean Test(Boolean value, Boolean negation) {
return negation ? !value : value;
}
Run Code Online (Sandbox Code Playgroud)
所以value
被否定仅当negated
是真实的.否则value
返回它是真还是假.
是否有任何操作员可以替代我正在做的事情?
我正在使用Entity Framework Core,我有以下内容:
String expression = "Country;User;User.Country"
Run Code Online (Sandbox Code Playgroud)
这表示在查询中包含Country,User和User.Country:
var q = context.Jobs
.Include(x => x.Country)
.Include(x => x.User).ThenInclude(x => x.Country);
Run Code Online (Sandbox Code Playgroud)
我不知道将包含什么表达式.我只知道它将是一个实体列表,有或没有子实体(例如:User.Country),我需要构建包含表达式.
有没有办法做到这一点?
我有以下Angular代码
控制器:
app.controller('MainCtrl', function($scope) {
var vm = this;
vm.job = null;
vm.create = function (job) {
vm.job = job;
}
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div ng-controller="MainCtrl as vm">
<span data-ng-bind="vm.job.position"></span>
<form name="form" data-ng-submit="vm.create(vm.job)">
<label for="position">Position</label>
<input id="position" name="vm.job.position" type="text" data-ng-model="vm.job.position" />
<button>Create</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
但是当我提交表单时,我没有看到位置值.
知道为什么吗?
我有以下表格
create table dbo.Users (
UserId int identity not null,
Name nvarchar (400) not null
)
create table dbo.Posts (
PostId int identity not null,
UserId int not null,
Title nvarchar (400) not null,
Content nvarchar (max) not null,
)
Run Code Online (Sandbox Code Playgroud)
在表上Posts UserId是该帖子的作者,它是一个FK到Users.UserId PK.
在这种情况下,我应该将列UserId命名为明确的关系是什么,或者AuthorId描述它是否与帖子有关?
这种命名最常用的方法是什么?
我有以下实体:
public class Position
{
public Int32 Id { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
public class Role
{
public Int32 PositionId { get; set; }
public Int32 UserId { get; set; }
public virtual Position Position { get; set; }
public virtual User User { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我需要把所有Positions
具有Role
用UserId = userId
.
我使用以下方法使其工作:
positions = positions
.Where(x => x.Roles.Select(y => y.UserId).Contains(userId));
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做SelectMany
?好点吗?
请注意,我需要返回位置......这是我使用时的问题SelectMany
.
在 Angular 7 应用程序上,我有以下模板:
<div *ngIf="avatarUrl$ | async;">
<ng-container *ngIf="avatarUrl$ | async as avatarUrl">
<img [src]="avatarUrl ? avatarUrl : 'avatar-default.png'">
</ng-container>
</div>
Run Code Online (Sandbox Code Playgroud)
将avatarUrl$
作为从数据库中通过服务获得是可观察到的。
我只想在avatarUrl$
加载值后显示 IMG 。
但是,有时从服务中获得的值是未定义的。
在这种情况下,我需要显示默认头像,例如:avatar-default.png
。
问题是未定义avatar-default.png
时不显示avatarUrl$
。
我认为因为这种情况与未加载和正在加载但未定义的值没有区别?
<div *ngIf="avatarUrl$ | async;">
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
c# ×4
angularjs ×2
javascript ×2
linq ×2
angular ×1
angular7 ×1
jquery ×1
sql ×1
sql-server ×1
t-sql ×1