I am using underscore.js to put my EJS values to template.
I am getting unexpected token if error
When i click on the error i am getting x.for and for each ananymous function.this is code below
enter code here
var a; is and array of objects.
_.each(a,function(b){
var tem=_.template('$('#id1').html());
$('.c').append(tem(p:b));}
any idea what's going wrong?
Related
Controller Code:
$tokenAmount = json_decode($token->getBody())->result;
return view('account')->with(compact('tokenAmount'));
View Code:
<label>Wallet Balance {{tokenAmount}}</label>
When I run the code. I'm getting following error.
Use of undefined constant tokenAmount - assumed 'tokenAmount'
PS: I tried following method also.
$tokenAmount = json_decode($token->getBody())->result;
return view('account', compact('tokenAmount'));
If I do echo $tokenAmount, it is printing the value without any error.
Please update your view code and check like:
<label>Wallet Balance {{tokenAmount}}</label>
to
<label>Wallet Balance {{$tokenAmount}}</label>
I'm trying to save null value in JSON into postgresql. When I use the following code:
resume = Resume.create!({
parsedres: {"Resume":{"xml:lang":"en","xmlns":"http://ns.hrxml.org/2006-02-28","xmlns:vos":"http://noresm.com/hr-xml/2006-02-28","ResumeId":{"IdValue":null}}}
})
I get an error:
NameError: undefined local variable or method `null' for main:Object
The issue is I get API data without "" for null and when I use JSON.parse
resume.parsedres = JSON.parse(response.body)
resume.save
It throws the
JSON::ParserError: 765: unexpected token at '<ParseResumeResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Code>Ack</Code><SubCode>Authentication/SubCode><Message>AccountID.</Message><CreditsRemaining>100</CreditsRemaining></ParseResumeResponse>'
Why does JSON.parse not interpret null?
In the first example you provided, the parsedres is not JSON but a Ruby Hash literal. Since the literal is Ruby code, you'd need to use Ruby's nil keyword instead of null:
resume = Resume.create!({
parsedres: {"Resume":{"xml:lang":"en","xmlns":"http://ns.hrxml.org/2006-02-28","xmlns:vos":"http://noresm.com/hr-xml/2006-02-28","ResumeId":{"IdValue":nil}}}
})
If you received a JSON string from the API, you should be able to parse it using the code you listed above:
require 'json'
resume = Resume.create!({
parsedres: JSON.parse('{"Resume":{"xml:lang":"en","xmlns":"http://ns.hrxml.org/2006-02-28","xmlns:vos":"http://noresm.com/hr-xml/2006-02-28","ResumeId":{"IdValue":null}}}')
})
Based on the exception being thrown, it looks like the response.body is XML data, not JSON.
In an attempt to learn using events I have followed this tutorial
In my App\Events\ThingWasDone.php i have this
Session::put('testevent', 'it works!');
$author= Entity::find(261);
$author->still_active_URL = 99;
$author->save;
The Session is properly defined and I can get it in my View files.
Any attempt to write to DB produces this error:
LogicException in Model.php line 2632:
Relationship method must return an object of type
Illuminate\Database\Eloquent\Relations\Relation
I tried options like passin or not passing any variable:
\Event::fire(new ThingWasDone($object->id));
\Event::fire(new ThingWasDone());
Didn't help.
Any hint?
change
$author->save;
to:
$author->save();
This might solve the error.
I really like how the error messages include a text string representing what the ReQL code looks like. Is it possible to get at this without forcing an error?
Example Error message:
RqlRuntimeError: No attribute `colors` in object:
{...}
in:
r.db("r_g").table("items").group("collection").ungroup().map(function(var_0) { return var_0("group").object(var_0("reduction")); }).concatMap(function(var_1) { return var_1("colors"); })
I'm wanting to get at the value after "in:" shown before I run() the query.
You can use .toString() like query.toString() (without .run(...))
It should use the same code as the one used to generate backtraces.
I opened an issue this morning to add it in the docs, it is somehow missing -- https://github.com/rethinkdb/docs/issues/354
I'm trying to convert jquery into coffeescript but I'm getting syntax error
SyntaxError: unexpected REGEX
This is my code:
container = document.querySelector('#style-container');
msnry = new Masonry( container, {
// options
columnWidth: 200
itemSelector: '.item'
});
What am I doing wrong?
Thanks!
That's not CoffeeScript. This is CoffeeScript:
container = document.querySelector "#style-container"
msnry = new Masonry(container,
columnWidth: 200
itemSelector: ".item"
)
You can convert JavaScript to CoffeeScript using this tool.
The specific error is referring to the comment tag. // doesn't mean a comment in CoffeeScript, so it falls back to an empty regular expression. A more useful regular expression would be /[0-9]+/, however the contents are optional in CoffeeScript.
// this is a JS comment
# this is a CS comment
The error is you are using // for a comment instead of #.
In addition to that, you example still looks more like JavaScript than CoffeeScript, but that's the specific error you are getting. See also http://js2coffee.org/
CoffeeScript comments start with #, instead of //. As noted above the // is used for a blank regex. When learning CoffeeScript, I recommend http://coffeescript.org/ and the Try CoffeeScript tool, so that you can see the JavaScript that your CoffeeScript would give rise to.