小编Mig*_*ura的帖子

检查许多布尔值

我有很多布尔变量如下:

Boolean A;
Boolean B;
Boolean C;
Boolean D;
Boolean E;
Boolean F;
...
Run Code Online (Sandbox Code Playgroud)

我想确保它们都是假的,或者最多只有一个是真的.

如果不使用大量的IF,有没有快速的方法呢?

c#

0
推荐指数
2
解决办法
157
查看次数

使用Angular显示列表

我有以下代码:

<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并且没有调用它...

我错过了什么?

angularjs

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

Javascript中的分工和权力

我有以下代码将变量除以100并为其供电.

  var a = 1;

  var b = (a / 100) ^ 2;
Run Code Online (Sandbox Code Playgroud)

'b'中的值变为2,应该是0.01 ^ 2 = 0.0001.

这是为什么?

javascript

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

用div标签包装iframe标签

我有一些包含帖子内容的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)

javascript jquery

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

条件下的否定价值?

我有以下内容:

public Boolean Test(Boolean value, Boolean negation) {
  return negation ? !value : value;
}
Run Code Online (Sandbox Code Playgroud)

所以value被否定仅当negated是真实的.否则value返回它是真还是假.

是否有任何操作员可以替代我正在做的事情?

c#

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

动态添加包含表达式

我正在使用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),我需要构建包含表达式.

有没有办法做到这一点?

c# linq entity-framework entity-framework-core

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

提交有角度的表格

我有以下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)

但是当我提交表单时,我没有看到位置值.

知道为什么吗?

angularjs

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

为帖子作者命名FK

我有以下表格

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描述它是否与帖子有关?

这种命名最常用的方法是什么?

sql t-sql sql-server

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

使用Where和SelectMany

我有以下实体:

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具有RoleUserId = userId.

我使用以下方法使其工作:

positions = positions
  .Where(x => x.Roles.Select(y => y.UserId).Contains(userId));
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做SelectMany?好点吗?

请注意,我需要返回位置......这是我使用时的问题SelectMany.

c# linq entity-framework

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

检查 Observable 是否未定义

在 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)

我该如何解决这个问题?

angular angular7

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