On this page,
http://reactivex.io/rxjs/file/es6/Subscriber.js.html
why is the function below have brackets? Does it have any meaning?
[rxSubscriberSymbol]() { return this; }
Square brackets around a method name indicate this is a computed property name, see the docs on MDN here
Related
I am new to laravel. I am defining this route to an edit button:
<button class="btn btn-primary">Edit task</button>
The url is generated fine but the page is not found. I am returning a view with my TaskController#edit with this route:
Route::get('/editTasks/{{ $task->id }}', 'TaskController#edit');
Can someone help me out figuring what i am doing wrong?
When defining routes, the route parameters should only have one { around them. Also, you should not use a variable in the declaration but a name for the variable.
In your example, this could be a valid declaration:
Route::get('/editTasks/{id}', 'TaskController#edit');
More information can be found in the docs: https://laravel.com/docs/5.7/routing#route-parameters
It is also recommended to use route names, so the url can be automatically generated.
For example:
// Route declaration
Route::get('/editTasks/{id}', 'TaskController#edit')->name('tasks.edit');
// In view
Edit task
no you have to define in your route just like this :
Route::get('/editTasks/{id}', 'TaskController#edit');
you don't have $task in your route and you dont need to write any other thing in your route. in your controller you can access to this id like this :
public function edit($taskId) {
}
and only you do this
You need to use single { instead of double, so it needs to be the following in your route:
Route::get('/editTasks/{taskId}', 'TaskController#edit');
And in your edit function:
public function edit($taskId) { }
The double { in the template is correct as this indicates to retrieve a variable
Extra information/recommendation:
It is recommended to let the variable name in the route match the variable in your function definition (as shown above), so you always get the expected variable in your function. If they do not match Laravel will use indexing to resolve the variable, i.e. if you have multiple variables in your route pattern and only use one variable in the function it will take your first route parameter even if you might want the second variable.
Example:
If you have a route with the pattern /something/{var1}/something/{var2} and your function is public function test($variable2) it would use var1 instead of var2. So it it better to let these names match so you always get the expected value in your function.
It's better to use "Route Model Binding". Your route should be like this:
Route::get('/editTasks/{task}', 'TaskController#edit');
And in Controller use something like this:
public function edit($task){
}
How to find a particular object in a array.
Below is my code
r.table("tablename").filter(
function(doc){
return r.expr(["value1","value2"]);
});
You have forgotten to add .contains in return statement. Try the rectified one -
r.table("tablename").filter(
function(doc){
return r.expr(["value1","value2"]).contains(doc("someKey"));
});
below 'throttle' code works good. But my question is that why we are using 'this' keyword in throttle function.
what is it actually?
please describe it.
thank you very much
$("document").ready(function(){
$("input").keypress(throttle(function(e){
$(".div1").html($("#ip").val());
},1000))
function throttle(fn,dly){
var timer=null;
return function(){
clearTimeout(timer);
timer=setTimeout(function(){
fn.apply(this,arguments);
},dly);
}
}
});
fn is a function. You can call the function in the standard way - fn() or you can call the call method or apply method on it.
When calling call or apply you have the option with the first argument to set the scope the function can be called in. The scope can also be set to null for no scope.
In my laravel 4 project users can submit textarea data. I know I can escape user data with {{{ }}} in my views,
But what should i do if i get the data with ajax ? It is a jquery variable i cant escape it with the brackets. For example if I handle response from ajax like :
$.each(response, function( key, value )
{
$('#div').append('<div>'+value.notEscapedData+'<div>')
});
And the controller where the data comes from is for example.
$response = Data::all()
return $response;
You can either do it with javascript (and you will find plenty solutions on the internet. e.g. the link #Thrustmaster posted in the comments) or you can do it in Laravel.
When you use Blades triple curly braces {{{ }}} it compiles to a call to e() (which then calls htmlentities)
So you can use e('string-containing-html') to escape the string.
You could use a model attribute accessor for the escaping but I suppose you will need the string unescaped sometimes so here are a two other options:
toArray()
Override the toArray() method in your model
public function toArray(){
$array = parent::toArray();
$array['attribute_name'] = e($array['attribute_name']);
return $array;
}
This way every time the model gets converted into an array (which is used for converting it into JSON=, the property will be escaped.
Loop over it in your controller
$data = Data::all();
$data->each(function($d){
$d->attribute_name = e($d->attribute_name);
});
return Response::json($data);
I saw some sample code like this in Javascript. Is this AJAX?
(function() {
/*some code*/
})();
Thanks a lot!
Is this AJAX?
No. It's what's commonly referred to as an "immediately invoked function expression", or IIFE.
(function() {
/*some code*/
})();
//^^These parentheses cause the function to be executed
The wrapping pair of parentheses cause the construct to be an expression, rather than a declaration. That's necessary because you can't have an anonymous function declaration (you'd get a syntax error).
They are commonly used to introduce a new scope (producing what you may have heard referred to as a closure).