小编Viv*_*shi的帖子

在webpack build中包含git commit hash和date

我正在使用react/es6/webpack.我想在我的应用程序中的某处显示构建和git哈希的日期.什么是最好的方法?

ecmascript-6 reactjs webpack angular

28
推荐指数
3
解决办法
8485
查看次数

laravel 5中的简单websocket实现

我需要在Laravel中实现非常简单和非常基本的websocket,以实现我的phonegap应用程序作为客户端和我的Laravel网站作为服务器之间的数据同步过程.我按照本教程http://www.binarytides.com/websockets-php-tutorial/来实现和测试websocket,它的工作原理.像这个我需要非常简单的laravel实现,我可以从js客户端调用我的控制器方法.客户端将是我的phonegap应用程序.我在laravel中找到了一些包含websocket的软件包,但是我发现很难实现它们.没有人与控制器交互,他们在这里和那里听事件和创建类,但在控制器中没有.我已经在Controller中编写了所有逻辑并使用ajax请求对其进行了测试,但现在我将通过websocket实现它,因为我需要双向通信来实现同步过程.我是Laravel的新手,所以请给我一些帮助.如果有人可以告诉我如何在laravel中集成about教程以便客户端可以直接调用控制器来发送数据,那将会非常棒.

php websocket cordova laravel-5 brain-socket

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

对不工作Angular 4的列进行ngx-DataTable排序

虽然我对角度非常新,但我在使用ngx-DataTable时遇到了一些困难.我使用简单的ngx-DataTable进行简单的操作.问题出在一个列上,虽然我已经将attr声明为[sortable] = true,但排序不起作用.这是代码.表定义:

 <ngx-datatable
                [columns]="columns"
                [columnMode]="'force'"
                [headerHeight]="40"
                [footerHeight]="50"
                [rowHeight]="'auto'"
                [limit]="10"
                [rows]='contacts'>
Run Code Online (Sandbox Code Playgroud)

DataTable包含两列,定义如下.

    <ngx-datatable-column
                        [width]="50"
                        [resizeable]="true"
                        [sortable]="true"
                        [draggable]="true"
                        [canAutoResize]="true" name="Name">
       <ng-template let-row="row" ngx-datatable-cell-template>
          <span>{{row.first_name}}</span>
       </ng-template>
   </ngx-datatable-column>

    <ngx-datatable-column
                        [width]="50"
                        [resizeable]="true"
                        [sortable]="true"
                        [draggable]="true"
                        [canAutoResize]="true" name="Actions">
        <ng-template let-row="row" let-rowIndex="rowIndex" ngx-datatable-cell-template>
      <!--Template Here-->
        </ng-template>
   </ngx-datatable-column>
Run Code Online (Sandbox Code Playgroud)

我只是想让我的名字列可以排序.请帮帮我们.提前致谢.

javascript ngx-datatable angular

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

使用 sequelize POST 方法在 nodejs 中插入新记录

我想使用 sequelize express 在数据库中插入新数据,无需查询。我很努力,但我没有得到输出......如果我的代码是错误的,那么给我一个使用 sequelize express 在 db 中插入新记录的代码。

const Sequelize = require('sequelize');
var express = require('express');
var app = express();
var mysql = require('mysql');
//var request=require('request')
const sequelize = new Sequelize('ganeshdb', 'root', 'welcome123$', {
    host: 'localhost',
    port: 3306,
    dialect: 'mysql'
});
var users = sequelize.define('users', {
    id: {
        primaryKey: true,
        type: Sequelize.INTEGER,
    },
    name: Sequelize.STRING,
    role: Sequelize.STRING,
    email: Sequelize.STRING
});
app.post('/test', function (request, response) {
    return users.create({
        name: request.body.name,
        role: request.body.role,
        email: request.body.email
    }).then(function (users) {
        if (users) { …
Run Code Online (Sandbox Code Playgroud)

methods post insert node.js sequelize.js

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

什么时候使用 socket.io?何时使用简单的 Http 调用?

我们正在使用Angular2/Node with Express 和 Mongo + MySql开发一个项目, 它非常大的应用程序,但不需要任何功能,例如实时通知或聊天

应用程序具有简单的 CRUD 操作并获取大量数据,所以我的问题是

使用 socket.io 而不是简单的 http 调用仍然很好/有好处吗?

据我了解 socket.io ,它只与服务器建立一次连接(握手),在我们的例子中,每次我尝试进行 api 调用时它都会握手?

那么将 socket.io 用于具有 CRUD 操作的正常应用程序有什么好处吗?它会节省时间吗?有什么速度差异吗?

哪种方式更好实施?

我经历过:何时使用 socket.io 何时使用 ajax

但是没有得到我想要的。

如果必须选择黑白简单的 http 调用和 socket.io ?哪一个更好 ?对于简单的 CRUD 操作,没有动态,不需要任何实时通知?在简单的情况下,哪个更好的性能,速度?

如果有时间/握手/请求-响应的任何性能图表或黑白对比会更好。

有人会帮我吗?提前致谢。

node.js socket.io angular

7
推荐指数
0
解决办法
5671
查看次数

使用 .env 文件进行变量赋值

我有一个 .env 文件,看起来像:

NODE_ENV = local
PORT = 4220
BASE_URL = "http://198.**.**.**:4220/"

PROFILE_UPLOAD = http://198.**.**.**:4220/uploads/profile/
POST_UPLOAD = http://198.**.**.**:4220/uploads/discussion/
COMPANY_UPLOAD = http://198.**.**.**:4220/uploads/company/
ITEM_UPLOAD  = http://198.**.**.**/uploads/item/
GROUP_UPLOAD  = http://198.**.**.**/uploads/group/
Run Code Online (Sandbox Code Playgroud)

我想做这样的事情:

NODE_ENV = local
IP = 198.**.**.**
PORT = 5000
BASE_URL = http://$IP:$PORT/

PROFILE_UPLOAD = $BASE_URL/uploads/profile/
POST_UPLOAD = $BASE_URL/uploads/discussion/
COMPANY_UPLOAD = $BASE_URL/uploads/company/
ITEM_UPLOAD  = $BASE_URL/uploads/item/
GROUP_UPLOAD  = $BASE_URL/uploads/group/
Run Code Online (Sandbox Code Playgroud)

的预期结果BASE_URLhttp://198.**.**.**:4220/

我尝试了很多语法但没有得到计算值

尝试过的语法:"${IP}", ${IP}, $IP

我使用dotenv package 来访问 env 变量。

environment-variables node.js express

6
推荐指数
2
解决办法
4577
查看次数

Datepicker 组件使用 @unform 和 react-datepicker 破坏编辑屏幕

我创建了以下组件来在 UnForm 中选择日期:

export default function DatePickerInput({ name, ...rest }) {
  const datepickerRef = useRef(null);
  const { fieldName, defaultValue = '', registerField } = useField(name);

  const [date, setDate] = useState(defaultValue || null);
  useEffect(() => {
    registerField({
      name: fieldName,
      ref: datepickerRef.current,
      path: 'props.selected',
    });
  }, [fieldName, registerField]);

  return (
    <Label htmlFor={fieldName}>
      <UnInput>
        <ReactDatePicker
          ref={datepickerRef}
          selected={date}
          onChange={setDate}
          dateFormat="dd/MM/yyyy"
          placeholderText="dd/mm/aaaa"
          writable="true"
          {...rest}
        />
      </UnInput>
    </Label>
  );
}
Run Code Online (Sandbox Code Playgroud)

为了保存记录,组件正常工作,加载并保存我选择的日期。当我要编辑记录时,尝试在初始加载中加载日期时,页面损坏并显示以下错误:

Unhandled Rejection (TypeError): Cannot assign to read only property 'selected' of object '#<Object>'
Run Code Online (Sandbox Code Playgroud)

如果我注释掉该行path: …

javascript reactjs react-datepicker unform

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

Angular 4中的升序和降序排序

为什么sort函数工作正常:

<th (click)="sort('transaction_date')">Transaction Date <i class="fa" [ngClass]="{'fa-sort': column != 'transaction_date', 'fa-sort-asc': (column == 'transaction_date' && isDesc), 'fa-sort-desc': (column == 'transaction_date' && !isDesc) }" aria-hidden="true"> </i></th>
Run Code Online (Sandbox Code Playgroud)

当这一个不工作时:

<th (click)="sort('user.name')">User <i class="fa" [ngClass]="{'fa-sort': column != 'user.name', 'fa-sort-asc': (column == 'user.name' && isDesc), 'fa-sort-desc': (column == 'user.name' && !isDesc) }" aria-hidden="true"> </i></th>
Run Code Online (Sandbox Code Playgroud)

HTML

 <tr *ngFor="let inner of order.purchase_orders | orderBy: {property: column, direction: direction}">
        <td>{{ inner.transaction_date | date  }}</td>
        <td>{{ inner.user.name  }}</td>
 </tr>
Run Code Online (Sandbox Code Playgroud)

TS

sort(property){
    this.isDesc = !this.isDesc; //change the direction    
    this.column = …
Run Code Online (Sandbox Code Playgroud)

angular-services angular-pipe angular

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

如何使用“findAll()”而不使用“raw:true”获取续集中的数据值?

当我在sequelize中使用findAll()而不使用raw:true时我想获取数据值

        Activities.findAll({
         include: [
         {       
           all: true         
          }   
         ],  
       })
        .then(activities => {   
        });
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js

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

"和"有什么区别?

嘿伙计们,我想知道这两种单引号'和'之间有什么区别?

我试图执行以下命令`然后它工作

axios.get(`https://api.github.com/users/${this.state.userName}`)
      .then(resp => {
        console.log(resp);
      });
Run Code Online (Sandbox Code Playgroud)

但当我试图使用''运行相同的命令它不起作用

axios.get('https://api.github.com/users/${this.state.userName}')
          .then(resp => {
            console.log(resp);
          });
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

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

Sequelizesync() + foregin key ,抛出错误

我有三个模型, user.model.js , user-log.model.js 和 address.model.js

它在我的数据库中创建表,但这里的 user_logs 和地址具有用户表的外键每次,当我删除所有表并运行节点服务器时,它都会抛出此错误

代码 :

用户模型.js

var User = db.sequelize.define( 'user' , {
    ......
});

module.exports = User;
Run Code Online (Sandbox Code Playgroud)

用户日志.model.js

var User = require('./user.model');

var Userlog = db.sequelize.define( 'user_log' , {
    user_id : {
        type: db.Sequelize.INTEGER,
    }
    ........
);


Userlog.belongsTo(User,{foreignKey: 'user_id'});
User.hasMany(Userlog,{foreignKey: 'user_id'});

Userlog.sync();

module.exports = Userlog;
Run Code Online (Sandbox Code Playgroud)

地址.model.js

var User = require('./user.model');

var Address = db.sequelize.define('address' , {
    user_id : {
        type : db.Sequelize.INTEGER,
    }
    ......
);

Address.belongsTo( User , {foreignKey: 'user_id'} );
User.hasMany( Address …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express sequelize.js

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

Angular4:选择[选定]第一次无效

有一个代码:

<select name="department" class="form-control select" [(ngModel)]="departments" formControlName="departmentControl">    
    <option *ngFor="let department of departments" [ngValue]="department" [selected]="department.id == this.departmentid">
      {{ department.name }}
    </option>
  </select>
Run Code Online (Sandbox Code Playgroud)

和功能:

isSelected(department): boolean {
  debugger;
  return department.id == this.departmentid;
}
Run Code Online (Sandbox Code Playgroud)

部门-是用户详细信息组件的嵌套组件。首次选择用户详细信息组件后,未选择部门。但是第二次一切正常。哪里有错?

angular angular4-forms

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

使用 [(ngModel)] 2 路数据绑定与 ngFor ,数组不会更新行的值

我已经建立了这个表格: 在此处输入图片说明

这是html代码:

<table class="table table-hover table-bordered table-striped table-highlight">
  <thead>
    <tr>
      <th *ngFor="let cell of tableData2.headerRow">{{ cell }}</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let row of tableData2.dataRows">
      <td *ngFor="let cell of row">
        <input type="text" class="form-control border-input" [(ngModel)]="cell" name="cell" />
      </td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

这是相关的打字稿代码:

declare interface TableData {
  headerRow: string[];
  dataRows: string[][];
}
public tableData2: TableData;
this.tableData2 = {
  headerRow: ['Version', 'Approbateur(nom+fonction)', 'Principales remarques', 'Date d\'approbation'],
  dataRows: [
    ['ahmed', '', '', ''],
    ['', '', '', ''],
    ['', '', '', ''],
    ['', '', …
Run Code Online (Sandbox Code Playgroud)

angular-ngmodel angular2-ngmodel ngmodel angular

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