如果与扩展运算符一起使用,则需要将属性分配给从接口定义的唯一属性。
我期待使用带有扩展运算符的打字稿构造函数的解决方案。
例如。
export interface IBrand {
id: string;
name: string;
}
export class Brand implements IBrand {
id: string;
name: string;
constructor(data: IBrand) {
this.id = data.id;
this.name = data.name;
}
}
Run Code Online (Sandbox Code Playgroud)
这是一种选择,所以当我像这样调用这个类时,不知道有多少成员,但我只id, name需要最终对象。
new Brand({...data })
Run Code Online (Sandbox Code Playgroud)
案例:但是当我有 25 个以上的键时 data
export interface IBrand {
id: string;
name: string;
}
export class Brand implements IBrand {
id: string;
name: string;
constructor(data: Partial<IBrand>) {
Object.assign(this, data);
}
}
Run Code Online (Sandbox Code Playgroud)
我不希望再次编写所有属性的构造函数。不管它有 25 个,它只是分配现有的属性将被分配。如果数据具有section, genre或任何其他属性,它将被忽略。
我的第二个片段不起作用。
我完全赞成ZEND FRAMEWORK.我试图安装,但收到了一些错误.
当我使用zf @ 1版本安装时.
C:\xampp\php将其命名为zendframework.include_path = ".;C:\xampp\php\PEAR;C:\xampp\php\zendframework\library"运行命令zf show version以zf错误结束,我的zend框架应该在include路径中.
zf create project zend_blog是否正确?我一直在尝试通过单击链接来实现数据库备份功能.我正在做的是将我的函数写入AppController&函数是...
public function backup($tables = '*') {
$this->layout = $this->autoLayout = $this->autoRender = false;
if ($tables == '*') {
$tables = array();
$result = $this->query('SHOW TABLES');
while ($row = mysql_fetch_row($result)) {
$tables[] = $row[0];
}
} else {
$tables = is_array($tables) ? $tables : explode(',', $tables);
}
foreach ($tables as $table) {
$result = $this->query('SELECT * FROM ' . $table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE ' . $table . ';';
$row2 = mysql_fetch_row($this->query('SHOW CREATE TABLE ' . …Run Code Online (Sandbox Code Playgroud) 我希望在cakephp的控制器中验证.虽然我的验证在模型中运行良好,但我不希望在控制器中验证它.
我在控制器中做了什么验证.
$validates = array('email' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A email is required'
),
'isUnique' => array(
'rule' => array('notEmpty'),
'message' => 'This email is already registered'
),
'email' => array(
'rule' => array('email'),
'message' => 'Enter valid mail address'
)
));
if ($this->User->validates($validates)) {
die("Action can be performed as validated !! Fields are correct");
} else {
die("Action can't be performed !! Fields are in-correct");
}
Run Code Online (Sandbox Code Playgroud)
如果字段是正确的话,它总是以正确的条件结束我.请帮忙
我希望使用 npm MySQL 创建到单独文件的连接。我希望每次触发查询时都将连接变量或池变量导出。如果我将另一个文件分开,我当前的方法每次都会重新创建连接。
//connection.js
'use strict';
var mysql = require('mysql');
var sys = require('util');
var exec = require('child_process').exec;
var config = require('config');
var db_config = {
host : config.get('databaseSettings.db_host'),
user : config.get('databaseSettings.db_user'),
password : config.get('databaseSettings.db_password'),
database : config.get('databaseSettings.database'),
port : config.get('databaseSettings.mysqlPORT'),
multipleStatements: true,
debug : ['ComQueryPacket']
};
var restart = function (callback) {
console.log('RESTART THE SERVER');
callback();
//exec("whoami; pm2 restart dashboard;", callback);
};
var handleDisconnect = function () {
connection = mysql.createConnection(db_config);
console.log('\n\n\t--In the handleDisconnect from connection to DB\n'); …Run Code Online (Sandbox Code Playgroud)