What's wrong here?
ExecJS::ProgramError: Error: Parse error on line 11: Unexpected '.'
.coffee
Person = Ember.Object.extend(
firstName: null
lastName: null
fullName: ->
firstName = #get("firstName")
lastName = #get("lastName")
firstName + " " + lastName
.property("firstName", "lastName")
)
Original .js
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');
return firstName + ' ' + lastName;
}.property('firstName', 'lastName')
});
You need to add braces when you call the method.
Person = Ember.Object.extend(
firstName: null
lastName: null
fullName: (->
firstName = #get("firstName")
lastName = #get("lastName")
firstName + " " + lastName
).property("firstName", "lastName")
)
It is true that they are optional in Coffeescript, but in this situation I think you need to explicitly add them. At least it was the only way I could get it to compile. Perhaps a Coffeescript expert can enlighten as to why.
Related
First image
i have used list with mvvm but my seniors told me use
dict<string, Employee> =
{
{"Employee 1" ,{id, emailid , name , father name , employee id , adddress}}
{"Employee 2" ,{id, emailid , name , father name , employee id , adddress}}
{"Employee 3" ,{id, emailid , name , father name , employee id , adddress}}
{"Employee 4" ,{id, emailid , name , father name , employee id , adddress}}
{"Employee 5" ,{id, emailid , name , father name , employee id , adddress}}
}
i am not able to change it to dictionary can anyone do it or give me some reference
Dictionaries are key-value collections. For every item, you have to specify a unique id.
For example:
var EmployeesDictionary = new Dictionary<string, Employee>();
EmployeesDictionary["empId"] = new Employee();
In your case you could populate your collection like that:
private record Employee(
int Id,
string EmpTab,
string EmailId,
string Name,
string FatherName,
string EmpId,
string Address);
private void LoadEmployees()
{
var EmployeesDictionary = new Dictionary<int, Employee>();
for (int i = 0; i < 5; i++)
{
EmployeesDictionary.Add(i, new Employee(
Id: i,
EmpTab: "EmptTab",
EmailId: "Email",
Name: "Name",
FatherName: "FatherName",
EmpId: "EmpId",
Address: "Address"));
}
}
You also could convert your list using LINQ:
private record Employee(
int Id,
string EmpTab,
string EmailId,
string Name,
string FatherName,
string EmpId,
string Address);
private void LoadEmplEmployees()
{
var EmployeesDictionary = new List<Employee>();
for (int i = 0; i < 5; i++)
{
EmployeesDictionary.Add(new Employee(
Id: i,
EmpTab: "EmptTab",
EmailId: "Email",
Name: "Name",
FatherName: "FatherName",
EmpId: "EmpId",
Address: "Address"));
}
EmployeesDictionary.ToDictionary(e => e.Id, e => e);
}
Dictionary Reference
LINQ ToDictionary Reference
main() {
CarsB cars = CarsB(lastname: 'Uysal', firstname: 'Kerem');
print(cars.firstname);
}
class Cars {
String firstname = '';
String lastname = '';
int yas = 0;
Cars(
this.yas, {
this.firstname = '',
this.lastname = '',
});
}
class CarsB extends Cars {
CarsB({String firstname = '', String lastname = ''})
: super(yas, firstname: firstname, lastname: lastname);
}
Why am I getting an error?
Error is:
Error: Undefined name 'yas'.
main.dart:51
: super(yas, firstname: firstname, lastname: lastname);
^^^
Exited (254)
CarsB({String firstname = '', String lastname = ''})
: super(yas, firstname: firstname, lastname: lastname);
Your CarsB constructor does not have a parameter called yas. So passing yas to the super constructor is a mistake. The compiler does not know what to do with it. When I call final b = CarsB(firstname: 'John', lastname: 'Doe'); what do you expect yas to be? It is undefined. And your compiler cannot compile that.
In my database I have last names and first names. I collect them in a array ; my variable lastAndFirstNameList contains: ex : [name, first name] => ( ["WOOD", "Robin"])
I then try to retrieve separately the last name and the first name with the variables lastname and firstname. I get the result « lastname undefined » and « firstname undefined ». I do not understand why! Could you help me please?
enter code here : //controller.js
Employee.getFirstAndLastName().$promise.then(function(result) {
var lastAndFirstNameList = result.list;
var lastname = lastAndFirstNameList.lastName;
var firstname = lastAndFirstNameList.firstName;
for(var k = 0; k < lastAndFirstNameList.length; k++)
{
console.log("lastname", lastname);
console.log("firstname", firstname);
}
console.log("lastAndFirstNameList", lastAndFirstNameList);
}
....
enter code here daoImpl.java
#SuppressWarnings("unchecked")
#Override
public List<Object> getFirstAndLastName() {
SQLQuery querySQL = sessionFactory.getCurrentSession().createSQLQuery("select last_name, first_name from employee");
List<Object> firstAndLastNameList = querySQL.list();
return firstAndLastNameList;
}
What does this give you? I don't think that 'firstname' and 'lastname' will give you anything because the are not referenced correctly.
Employee.getFirstAndLastName().$promise.then(function(result) {
var lastAndFirstNameList = result.list;
var lastname = lastAndFirstNameList.lastName;
var firstname = lastAndFirstNameList.firstName;
console.log("lastname ", lastname);
console.log("firstname ", firstname);
console.log("lastAndFirstNameList", lastAndFirstNameList);
}
Change the above reference variable to look like this:
var lastname = lastAndFirstNameList[0].lastName;
var firstname = lastAndFirstNameList[0].firstName;
That should give you the first value if passed correctly from the server.
Your loop should then look like this:
for(var k = 0; k < lastAndFirstNameList.length; k++){
console.log("lastname", lastAndFirstNameList[k].lastName);
console.log("firstname", firstname[k].firstName);
}
Suppose I want to set FullName property using string.Format like this:
var userList = users.Select(user => new User()
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName
FullName = string.Format("{0} {1}", user.UserName, user.FirstName)
}).ToList();
This obviously doesn't work because LINQ doesn't know about string.Format.
My question is what are the other options beside going over the list in memory and setting FullName for each item?
userList.ForEach(u => u.FullName = string.Format("{0} {1}", user.UserName, user.FirstName))
UPDATE: to see what I need, please see my conversation with #octavioccl below
you can use it:
FullName = user.UserName + " " + user.FirstName
But I think that it could be better solution (of cource if it's possible for you):
public class User
{
public int Id {get;set;}
public string UserName {get;set;}
public string FirstName {get;set;}
public string LastName {get;set;}
public string FullName
{
get
{
return string.Format("{0} {1}", FirstName, LastName);
}
}
}
then in your query build it:
var userList = users.Select(user => new User()
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName
}).ToList();
String.Format is not supported in EF, try this way:
FullName = user.UserName + " " + user.FirstName
In this link you will find all CLR methods that are supported
Another object is to project to an anonymous type without that property, then project to the final type in linq-to-objects:
var userList = users.Select(user => new {
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName
})
.AsEnumerable()
.Select(user => new User()
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName
FullName = string.Format("{0} {1}", user.UserName, user.FirstName)
})
.ToList();
I've just started learning TypeScript and I'm having a hard time wrapping my head around an interface behavior from the beginning tutorial on http://www.typescriptlang.org/Playground/#tut=ex5
As I understand it, the interface should enforce the type of the parameters, however this particular line throws me off
var user = new Student("Jane", "M.", "User");
It compiles correctly and all is well, but when I modify it to
var user = new Student(1, 2, 3);
it also compiles just fine.
Could anyone elaborate why it's working ?
I understand that this is a beginners question but I could not find any info on this searching online and I don't have any TypeScript experts around me.
Thanks in advance,
Eugene
The type of the Student constructor parameters is any because there is no type annotation:
class Student {
fullname : string;
constructor(public firstname, public middleinitial, public lastname) {
this.fullname = firstname + " " + middleinitial + " " + lastname;
}
}
If we change it to have some type annotations, we'll get an error:
class Student {
fullname : string;
constructor(public firstname: string, // <-- add ': string' here
public middleinitial: string, // and here
public lastname: string) { // and here
this.fullname = firstname + " " + middleinitial + " " + lastname;
}
}
var x = new Student(1, 2, 3); // Error