考虑以下代码:
function Foo() {
return "something";
}
var foo = new Foo();
Run Code Online (Sandbox Code Playgroud)
根据 JavaScript 专家的说法,他们说从构造函数返回“nothing”或“this”。这是什么原因?
我知道当使用“new”时,“this”将被设置为构造函数的原型对象,但无法单独理解这一点。
如何使用 PHP 回显 AdSense 代码?这是我正在为 codeigniter php 工作的代码示例。
$adsence = "
<div class=\"right-inner\">
<center width=\"96% class=\"img-responsive center-block\">
<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>
<!-- quiz_net -->
<ins class=\"adsbygoogle\"
style=\"display:block\"
data-ad-client=<?php echo $client ?>
data-ad-slot=<?php echo $slot ?>
data-ad-format=\"auto\"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>
</div>";
echo $adsence;
Run Code Online (Sandbox Code Playgroud)
我只想用 PHP 在 div 中插入 adsense 代码。我还尝试使用 htmlentities 和 stripslashes,但没有显示广告。
我正在使用 vuejs 并创建/删除 dynamic select,它工作正常。
这是工作小提琴:https : //jsfiddle.net/nikleshraut/fgpdp700/2/
var vm = new Vue({
el: "#app",
data: {
optionArr: [{id:1,price:100},{id:2,price:200}],
options: [{id:1,value:'option1'},{id:2,value:'option2'},{id:3,value:'option3'}]
},
mounted() {
console.log("help!!!!");
//$("#opt_select_0,#opt_select_1").select2();
},
methods: {
addOption: function(){
var index = Object.keys(this.optionArr).length;
this.optionArr.push({id:'',price:''});
setTimeout(function(){
//$("#opt_select_"+index).select2();
},100);
},
deleteOption: function(index){
this.optionArr.splice(index, 1);
},
getAll: function(){
console.log(this.optionArr);
}
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.8/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.css">
<div id="app">
<div>{{ $data.optionArr }}</div>
<template v-for="(user_option,index) in optionArr">
<select class="applySelect2" v-bind:id="'opt_select_'+index" on-change="print" v-model="user_option.id">
<template v-for="option in options"> …Run Code Online (Sandbox Code Playgroud)我目前正在使用laravelcollective插件渲染和填充laravel 中的表单.这是按预期工作:
{!! Form::model($user, ['action' => 'user@updateUser']) !!}
<div class="form-group">
{!! Form::label('user_name', 'Name') !!}
{!! Form::text('user_name') !!}
</div>
<button class="btn btn-success" type="submit">Update</button>
{!! Form::close() !!}
Run Code Online (Sandbox Code Playgroud)
上面的代码生成表单并使用用户名填充输入字段.
如果我想将一个类属性添加到表单输入,如下所示:
{!! Form::text('user_name', '', ['class' => 'form-control']) !!}
Run Code Online (Sandbox Code Playgroud)
它没有填充输入值,因为理论上我已将默认值(第二个参数)设置为''.
有没有一种方法可以填充值并添加一个类而不显式地这样做:
{!! Form::text('user_name', $user->user_name, ['class' => 'form-control']) !!}
Run Code Online (Sandbox Code Playgroud)
通过这样做上述这违背了通过模型呈现形式的对象{!! Form::model($user, ['action' => 'user@updateUser']) !!},因为我可能也解析$user为一个变量到模板,我不想做的事.
我在vuejs中使用select2,我发现vuejs不能使用jquery select2,因为vuejs正在使用navite html.
我正在使用此代码
Vue.directive('select', {
twoWay: true,
bind: function () {
$(this.el).select2()
.on("select2:select", function(e) {
this.set($(this.el).val());
}.bind(this));
},
update: function(nv, ov) {
$(this.el).trigger("change");
}
});
var app = new Vue({
el: '#app',
data: {
supplier_id: "niklesh"
}
})
$('#supplier_id').select2({});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.4/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/css/bootstrap.css">
<div id="app">
{{ supplier_id }}
<select id="supplier_id" class='form-control' v-model='supplier_id' v-select='supplier_id'>
<option value="atul">Atul</option>
<option value="niklesh">Niklesh</option>
<option value="sachin">Sachin</option>
</select>
</div>Run Code Online (Sandbox Code Playgroud)
请分享您的回复以解决此问题.
现状:我们正在创建新的数据库进行新的注册。
问题:如果在数据库迁移中进行了任何更改,我们需要对以前创建的数据库进行处理。或为每个先前创建的数据库运行该迁移。
如果我们为每个数据库运行迁移都没有问题。
问题:如何检查数据库表中有要在查询中应用条件的列。
当前,我需要先对第一行触发两个查询,并检查该列的存在,然后在where子句中应用条件。像下面
$firstRow = Model::first();
if(isset($firstRow->is_splited)){
$records = Model::where('is_splited',0)->get(); // this will give error if I don't check column existence for previously created database.
}else{
$records = Model::all();
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以在一个查询中实现。还是有更好的方法呢?
感谢您的宝贵时间和建议。
我正在为表单使用Laravel Collective,每当验证字段失败时,我都需要添加一个类。默认字段如下所示:
{{ Form::text('name', null, ['class' => 'form-control']) }}
Run Code Online (Sandbox Code Playgroud)
每当验证失败时,我都需要添加border-danger到该类中:
{{ Form::text('name', null, ['class' => 'form-control border-danger']) }}
Run Code Online (Sandbox Code Playgroud)
但是我不能简单地@if ($errors->has('name'))在那个{{ Form }}领域内做。
有没有简单的方法可以做到这一点?我不想做的一件事就是这样的事情:
@if ($errors->has('name'))
{{ Form::text('name', null, ['class' => 'form-control border-danger']) }}
@else
{{ Form::text('name', null, ['class' => 'form-control']) }}
@endif
Run Code Online (Sandbox Code Playgroud) 我有一个项目的清单,相关的类别(表名是:items)
--- id ------ category_id ----- name
--- 1 ------- 1 ---------------- aa --> Valid
--- 2 ------- 1 ---------------- bb --> Valid
--- 3 ------- 2 ---------------- aa --> Valid
--- 4 ------- 2 ---------------- bb --> Valid
--- 5 ------- 1 ---------------- aa --> InValid because same name exist in same category
--- 6 ------- 2 ---------------- bb --> InValid because same name exist in same category
Run Code Online (Sandbox Code Playgroud)
唯一规则在这里不起作用,因为类别明智,它对name所有记录进行验证。
public function validateItems($requestAll){ …Run Code Online (Sandbox Code Playgroud) 我刚来了accros这段代码:
var indx, hash;
loop:
for (var i in config.users) {
if (config.users[i].email === dataValues.email) {
indx = i;
hash = config.users[i].hash;
break loop;
}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的代码吗?什么是"循环:"?谷歌'js循环'很难,而不仅仅是看到... in/while循环的常规
我试图在chart.js中放置矩形来制作上下范围/级别,就像在图像中一样
虽然我可以通过在这个例子中画两条线来实现
var ctx = document.querySelector("#myChart").getContext('2d');
Chart.pluginService.register({
afterDraw: function(chart) {
if (typeof chart.config.options.lineAt != 'undefined') {
var lineAt = chart.config.options.lineAt;
var ctxPlugin = chart.chart.ctx;
var xAxe = chart.scales[chart.config.options.scales.xAxes[0].id];
ctxPlugin.strokeStyle = "green";
ctxPlugin.beginPath();
lineAt = 102;
ctxPlugin.moveTo(xAxe.left, lineAt);
ctxPlugin.lineTo(xAxe.right, lineAt);
ctxPlugin.moveTo(xAxe.left, lineAt-33);
ctxPlugin.lineTo(xAxe.right, lineAt-33);
ctxPlugin.stroke();
}
}
});
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Nov","Dec"],
datasets: [{
label: 'Findings',
data: [0,45],
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}]
},
options: …Run Code Online (Sandbox Code Playgroud)