我需要一些迭代数组的帮助,我一直卡住或重新发明轮子.
values = [
{ name: 'someName1' },
{ name: 'someName2' },
{ name: 'someName1' },
{ name: 'someName1' }
]
Run Code Online (Sandbox Code Playgroud)
我怎样才能检查数组中是否有两个(或更多)相同的名称值?我不需要计数器,只需设置一些变量,如果数组值不唯一.请记住,数组长度是动态的,也是数组值.
我用搜索参数调用URL是动态的.我怎么能形成适当的Eloquent查询?
理论上:
我需要这种结构,所以如果param存在,我可以使用where子句.如果Laravel有其他方式,请告诉我.
我有优惠和服务表.
服务是优惠的子女.到目前为止,我已经建立了软删除优惠的功能.我如何软删除附加服务?这是我的代码:
迁移优惠
Schema::create('offers', function(Blueprint $table)
{
$table->increments('id')->unsigned();
...
$table->timestamps();
$table->softDeletes();
});
Run Code Online (Sandbox Code Playgroud)
移民服务
Schema::create('services', function(Blueprint $table)
{
$table->increments('id');
$table->integer('offer_id')->unsigned();
...
$table->timestamps();
$table->softDeletes();
});
Schema::table('services', function($table)
{
$table->foreign('offer_id')
->references('id')
->on('offers');
});
Run Code Online (Sandbox Code Playgroud)
型号优惠
use SoftDeletes;
protected $dates = ['deleted_at'];
public function services() {
return $this->hasMany('App\Service');
}
Run Code Online (Sandbox Code Playgroud)
模特服务
public function offer() {
return $this->belongsTo('App\Offer');
}
Run Code Online (Sandbox Code Playgroud)
删除方法
public function destroy($id)
{
$offer = Offer::find($id);
$offer->delete();
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我试图了解ng-if和范围.据我所知,ng-if创建了一个新的子范围.这是我的问题:
视图
<input ng-model="someValue1" />
<div ng-if="!someCondition">
<input ng-model="$parent.someValue2" />
</div>
Run Code Online (Sandbox Code Playgroud)
调节器
$scope.someCondition = true;
if ($scope.someCondition) {
$scope.someValue2 = $scope.someValue1;
}
Run Code Online (Sandbox Code Playgroud)
如果someCondition设置为true,则someValue2应与someValue1相同.
我的问题是我无法在两种情况下访问someValue2(true或false).我怎么能实现这个目标?
我有一个TypeScript错误:
类型'(element:Conversation)=> void'的参数不能分配给类型'的参数(值:Conversations,index:number,obj:Conversation [])=> boolean'.类型'void'不能分配给'boolean'类型.
这是我的架构
export class Conversation {
constructor(
public id: number,
public dateTime: Date,
public image: string,
public isUnread: boolean,
public title: string
) {}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码
// Mark as read also in data store
this.dataStore.data.find((element) => {
if (element.id === conversationId) {
element.isUnread = true;
// Push the updated list of conversations into the observable stream
this.observer.next(this.dataStore.data);
}
});
Run Code Online (Sandbox Code Playgroud)
这个错误意味着什么?提前谢谢你.
我正在使用Angular2及其ngFor.我想将类添加到奇数行和偶数行,因此我可以通过颜色将它们分开.
这是我的代码(实际上不起作用):
<div *ngFor="#meeting of meetingList; #index=index; #odd=odd; #even=even;"
class="row"
[ngClass]="{ odd: odd, even: even }
">
<div class="col"></div>
<div class="col"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
虽然如果我这样做,代码工作:
<div *ngFor="#meeting of meetingList; #index=index; #odd=odd; #even=even;"
class="row"
">
<div class="col" [ngClass]="{ odd: odd, even: even }"></div>
<div class="col" [ngClass]="{ odd: odd, even: even }"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法将类放入行而不是列?先感谢您.
我正在使用两个组件,我正在使用这种模式:子组件应尽可能保持隔离 - 它正在处理自己的验证错误.父组件应检查具有子项之间依赖关系的错误.所以,在我的情况下:password字段和password confirmation字段.
这是我的代码:
a)SignUp(父母)
设置初始状态.
constructor() {
super();
this.state = {
isPasswordMatching: false
};
}
Run Code Online (Sandbox Code Playgroud)
在render()方法中,我输出了我的子组件.通过道具称为callback我isPasswordMatching()通过绑定父母的传播方法this.目标是可以在子组件中调用该方法.
<TextInput
id={'password'}
ref={(ref) => this.password = ref}
callback={this.isPasswordMatching.bind(this)}
// some other unimportant props
/>
<TextInput
id={'passwordConfirm'}
ref={(ref) => this.passwordConfirm = ref}
...
Run Code Online (Sandbox Code Playgroud)
isPasswordMatching()方法是检查密码是否匹配(通过refs this.password和this.passwordConfirm)然后更新状态.请注意,此方法在child(password或passwordConfirm)内部调用.
isPasswordMatching() {
this.setState({
isPasswordMatching: this.password.state.value === this.passwordConfirm.state.value
});
}
Run Code Online (Sandbox Code Playgroud)
b)TextInput(孩子)
设置初始状态.
constructor() {
super();
this.state = {
value: '',
isValid: false
}; …Run Code Online (Sandbox Code Playgroud) 我无法将boolean值传递给我的指令.
这是我的HMTL:
<city-zip city="clientCity" zip="clientZip" requiredParam="'true'"></city-zip>
Run Code Online (Sandbox Code Playgroud)
指令:
.directive('cityZip', function() {
return {
restrict: 'E',
templateUrl: '../templates/templateCityZip.html',
scope: {
city: '=',
zip: '='
},
controller: function($scope) {}
}
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.
我安装了mongodb
brew install mongodb
Run Code Online (Sandbox Code Playgroud)
创建文件夹
mkdir -p /data/db
Run Code Online (Sandbox Code Playgroud)
处理权限
sudo chown -R `id -un` /data/db
Run Code Online (Sandbox Code Playgroud)
跑
mongod
Run Code Online (Sandbox Code Playgroud)
错误日志
2018-01-06T14:28:51.450+0100 I CONTROL [initandlisten] MongoDB starting : pid=6120 port=27017 dbpath=/data/db 64-bit host=Zigas-MBP-2
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] db version v3.6.1
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] git version: 025d4f4fe61efd1fb6f0005be20cb45a004093d1
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] allocator: system
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] modules: none
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] build environment:
2018-01-06T14:28:51.451+0100 I CONTROL [initandlisten] distarch: x86_64
2018-01-06T14:28:51.451+0100 …Run Code Online (Sandbox Code Playgroud) 我有两个分支:-master 和-develop。
我正在尝试将分支合并develop到master分支中。
我已经检查了 Tower 和 Araxis 合并,这两个分支是相同的。但是当我在 Github 上执行拉取请求时,我看到有 381 个文件被更改,就像文件根本不在 master 上一样。
任何想法为什么这种行为?
更新:我附上了拉取请求的截图。
angularjs ×2
eloquent ×2
laravel ×2
angular ×1
arrays ×1
git ×1
github ×1
javascript ×1
mongodb ×1
ngfor ×1
pull-request ×1
reactjs ×1
refs ×1
typescript ×1
unique ×1