小编bit*_*its的帖子

Bootstrap 4:隐藏卡片文本中的溢出

我有一张bootstrap 4卡,我想隐藏字幕的溢出(并显示"......").我怎样才能做到这一点?如果可能,使用纯引导代码......

<div class="card-block p-1">
    <p class="card-title">Test object</p>
    <p class="card-subtitle text-muted">Added by Someone with a long name</p>
    <p class="card-text mx-auto text-center"><span class="badge badge-pill badge-danger">€ 800</span></p>
</div>
Run Code Online (Sandbox Code Playgroud)

overflow bootstrap-4

5
推荐指数
1
解决办法
6586
查看次数

NodeJS:如何实现存储库模式

我想在我的 NodeJS 应用程序中实现存储库模式,但我遇到了循环需求的麻烦(我猜......)。

我如何尝试实现它:

  • PersonRepository 类,具有以下方法:getAll、getById、create、update、delete
  • Person 类具有以下方法:init、createAccount、showRelations、addRelation、

首先:我的存储库模式设计正确吗?

我的课程:

personRepository.js

const PersonModel = require('./model');
const Person = require('./person');

class PersonRepository {

    constructor() {
        this._persons = new Set();
    }

    getAll( cb ) { // To Do: convert to promise
        let results = new Set();

        PersonModel.find({}, 'firstName lastName', (err, people) => {
            if (err) { 
                console.error(err);
            }
            people.forEach((person, index) => {
                let foundPerson = new Person(person._id.toString(), person.firstName, person.lastName, person.email, person.birthday);
                results.add(foundPerson);
            });
            this._persons = results;
            if (cb) cb(this._persons);
        });
    }

    getById(id) …
Run Code Online (Sandbox Code Playgroud)

repository-pattern node.js

5
推荐指数
1
解决办法
2万
查看次数

angularjs 1.x:使用$ http.post发送{'key':undefined}

我的要求是,我希望能够{title: "test", price: undefined}通过$ http.post从我的angular-app中将一个对象发送到我的nodejs应用程序(以便能够通过mongoDB中的Mongoose更新删除价格键)。

问题:

代码提取

console.log(object)
$http.post(url, object)
Run Code Online (Sandbox Code Playgroud)
  1. 在控制台中,我看到: {title: "test", price: undefined}
  2. 我的请求有效载荷包含 {title: "test"}

==>为什么我的有效载荷不包含完整的对象?如何添加价格:有效载荷中未定义?

http angularjs

3
推荐指数
1
解决办法
405
查看次数

angularJS:ui-router $ state.go仅适用于第一次点击

我正在努力学习如何使用AngularJS,我偶然发现了一个我无法解决的问题......

下面的代码应该: - 显示2个视图:1显示左侧的一些名称("接收者")和一个显示主要内容(一个介绍或相应人员的列表("currentReceiver")) - 通过$导航state.go到相应的"wishlist"并将URL更改为"... /#/ wishlist /"

我的代码似乎只有在我第一次点击名字时才有效...一旦我点击一次,网址就会保持为空('... /#/')并显示介绍页面......

有人可以解释一下我做错了什么或者我应该在哪里调试这个问题......?

我的index.html的一部分

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-3 col-md-2 sidebar" ui-view="wishlists">
            </div>
            <div class="col-sm-20 col-sm-offset-3 col-md-10 col-md-offset-2 main" ui-view="wishes">
            </div>
        </div>
    </div>

    <!-- scripts -->
    ...     

</body>
Run Code Online (Sandbox Code Playgroud)

wishlist.tmpl.html (左侧的视图'wishlist'模板希望链接到functon"setCurrentReceiver")

<ul class="nav nav-sidebar">
    <li ng-repeat="receiver in receivers" ng-class="{'active': isCurrentReceiver(receiver)}">
        <a href="#" ng-click="setCurrentReceiver(receiver)">{{receiver.name}}</a>
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

gimmi-app.js (在函数setCurrentReceiver中使用$ state.go)

angular.module('Gimmi', [
    'ui.router',
    'wishlist',
    'wishlist.wish',
    'wishlist.receiver'
])
.config(function($stateProvider, $urlRouterProvider){
    $stateProvider
        .state('gimmi', {
            url: '',
            abstract: true
        })
    ;
    $urlRouterProvider.otherwise('/');
})

.controller('MainCtrl', function ($scope, …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-ui-router

2
推荐指数
1
解决办法
738
查看次数

Angular + Ngrx:在组件和函数中选择值的最佳实践

我有与ngrx get value in function几乎相同的问题,但我想知道答案(请参阅该主题中的评论)是否仍然是当今的最佳实践。

我的情况是:

  1. 我想从商店获取 2 个值以显示在我的组件中 --> 我使用选择器和异步管道
  2. 我需要将这些相同的值传递给 Angular Material 对话框,以便在对话框组件中使用它们。

我有一个可行的解决方案:我在 ngOnInit() 中使用订阅函数,并使用 Observable 中的值设置一个局部变量。因此,我不再需要使用异步管道,我可以轻松地将值传递给某些函数...这听起来像是最好的选择,但在我寻找答案的任何地方,我都会看到“避免使用订阅”。

所以我想知道:

  • 有没有更好的方法来处理这种情况?
  • 或者这是“处理这种情况的 ngrx/rxjs 方式”?
  • 或者我是否使用选择器 Observable 和异步管道来显示组件中的值并订阅 Observable 以创建一个局部变量来传递给我的函数(这似乎有点多余......)
  • 或者 ...?

我的问题是我想要一种一致的方法来处理 ngrx 值,但现在看起来我需要根据情况使用两种方法:

  • 用于显示组件中的值的异步管道(社区的首选方法)
  • 在本地函数中使用值时的订阅(社区建议“除非必要”不要使用订阅)

(令我惊讶的是:很难在互联网上找到明确的答案......)

redux ngrx angular angular-ngrx-data rxjs-observables

2
推荐指数
1
解决办法
2203
查看次数

Javascript:使用 Promise 时需要帮助防止代码重复

我想知道如何防止复制以下代码中的代码。我复制了这个函数wishModel.createWish()。复制代码的原因是:

  • 在 if 部分中,必须在解决 Promise(打开模式)后触发该函数
  • 在 else 部分,函数立即执行

感谢您帮助我改进我的代码!

    if (copyExistsOnList) {
        var copyWarningPopup = $uibModal.open({...});

        copyWarningPopup.result.then(function (wish) {
            wishModel.createWish(newWish, userID, userID, wish._id);
        });
    } else {
        wishModel.createWish(newWish, userID, userID, wish._id);
    }
Run Code Online (Sandbox Code Playgroud)

javascript promise

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