How can I use fromJson to List inside Map? - dart

Usually, I will use this code to make to list.
jsonMap.map((gallery) => new Gallery.fromJson(gallery)).toList();
But I don't know how to use with a fromJson.
This is a picture of my code.

I have solved this problem by using.
List.castFrom(json['galleries']).map((gallery) => new Gallery.fromJson(gallery)).toList();

Related

ZF2 Custom query

Hello and good morning to you all,
I am following the qickstart tutorial from Rob Allen in the manual.
I am trying to change some things. One of the things I am trying to do is to get a query like this:
"SELECT max(id) FROM Albums";
I tried things like
$this->select();
$this->columns(array('id' => 'MAX(id)'));
Apparently this is not the way to do it.
I probablly need some expression object or so.
Can anyone tell me how to solve this?
EDIT (forget the above)
This whole code is based on the quickstart in the manual (ZF2)
I have managed to write a query like this:
$select = $this->getSql()->select();
$select->columns(array(new Expression('max(id) as MaxId')));
$rowset = $this->selectWith($select);
$row = $rowset->current();
return $row;
The result of this is an empty object.
But when i change
$select->columns(array(new Expression('max(id) as MaxId')));
to
$select->columns(array(new Expression('max(id) as id')));
then i get back an object with the id as 1. Which is the max(id).
But when I add in my album object in the function exchangeArray one line with maxId, then it returns the maxId field.
BUT, it can't be that i need to do this everytime i just want to do a query like this. Is this really the way it works?
Use Zend\Db\Sql\Expression
So if i see this correctly (which may not be the case) you'd do it like you just did, but wrap the SQL-Expression into new Expression('max(id)). So it should be like the following
use Zend\Db\Sql\Expression;
//...
$this->columns(array(
'maxid' => new Expression('max(id)')
));
If the syntax like this is wrong, please don't curse me, but i would assume that knowing about the Sql\Expression will already help you ;)

Using optgroup in sfWidgetFormPropelChoice since the values of a column

I'm in a project that uses Symfony 1.2 (I know this is quite old, but I can't do anything about this).
I have a sfWidgetFormPropelChoice widget which feed its options from a foreign key than exists say in table A. I would like to group that foreign key since another column in table A, with the optgroup HTML element.
So I have something like that:
$this->widgetSchema['B_has_A_list'] = new sfWidgetFormPropelChoiceMany(array(
'model' => 'TableA',
));
And I would like to have something that easy:
$this->widgetSchema['B_has_A_list'] = new sfWidgetFormPropelChoiceMany(array(
'model' => 'TableA',
'optgroup' => 'ColumnInTableA', //That's not possible. It would group options grouping by ColumnInTableA using the optgroup HTML element
));
Do you know another easy way to achieve this. Or do you know any extended sfWidgetFormPropelChoice that achieve this?
Thank you.
Ok, I extended the symfony widget to achieve this. If anybody is interesed, it's in github:
https://github.com/laMarciana/sfWidgetFormChoiceOptgroup
To use you have to define the same required options than sfWidgetFormPropelChoice plus a optgroup_columnoption with the PhpName of the column you want to use as the optgroups.
Ex:
$this->widgetSchema['field'] = new sfWidgetFormPropelChoiceOptgroup(array(
'model' => 'Table',
'optgroup_column' => 'Column',
));
I added as well a version for Doctrine.

How can i reload TTLaucherView with new items?

I am using Three20 for my new iOS project. I have impletemented TTLauncherView & TTTabStrip, and both are displaying correctly. Now i want to load new items in TTLaucherView on selection of TTTabStrip.
How should i go about it ? I can't find any relevant method to do this.
I'm a bit rusty on this but looking at code from one of my apps, it looks like you add to the self.launcherView.pages collection (not sure if this is the default way of doing this, but in my project, launcherView is a class derived from TTLauncherView).
self.launcherView.pages is an NSArray, where each index is an array of TTLauncherItems. So you add to an existing page or create a new page, and add TTLauncherItems to it.
Hope this helps!
strange ! I was also looking for answer to same question. Currently i am creating new TTLauncherView whenever selection is changed for tab items.
But i am looking for a better solution.

Check whether a variable is an Array

I want to find out whether a variable is an array or not
if (params.writtenLines == ???)
Much appreciated.
More importantly, why do you want to check whether it's an array? If you know the parameter might be a single string or a list, you can now use:
def lines = params.list("writtenLines")
That came with Grails 1.2.
This functionality is already available in pure Java and can therefore be used in Groovy, too:
if (params.writtenLines.class.isArray())
I realize this is a bit late, but what about this:
List.isCase(params.writtenLines)
Wouldn't it be a correct solution, too?

sfWidgetFormSchemaFormatter: Format for name of embedded form

Im trying to create a custom formatter in Symfony 1.4.
I have embedded form via
$this->embedRelation('User','BasesfGuardUserAdminForm');
Is there a way to format the name of the embedded form 'User'?
IIRC BasesfGuardUserAdminForm AS User.
I has the same issue, and when I replaced embedForm() by mergedForm() the errors became easy to manipulate.
I think this is most straight-forward! (and pretty obvious too!)
$this->embedForm('inner_form', new InnerForm());
$this->widgetSchema['inner_form']->setLabel('');
This will result in an empty label for the form!
foreach ( $answers as $a )
{
$aForm = new QuestionAnswerForm($a);
$this->mergeForm($aForm);
}
$this->widgetSchema->getFormFormatter()->setRowFormat('%field%%help%%hidden_fields%');

Resources