Is there a way of rendering a TagMod in a component - scalajs-react

Say I have a table defined as follows:
val cols = Seq("One", "Two", "Three")
<.table(
<.tbody(
<.tr(
rows.map(r => <.td(r)).toTagMod
)
)
)
And I want to wrap each row part in a component:
ScalaComponent.builder[Seq[String]]("Row")
.render_P(r => rows.map(r => <.td(r)).toTagMod)
.build
The code will not compile as render_P expects a VdomNode and not a TagMod. Is there of converting?

I figured out that I need to use toVdomArray in this context instead of toTagMod

Related

Type error when adding two derivatives of same base class in a List

I have this code:
List<Widget> _elementsHere = _locationsRegister
.map((e) => ShowingLocation(
num: e.num,
name: e.name,
icon: e.icon,
))
.toList();
I have specified List<Widget>, but if I print _elementsHere.runtimeType.toString() in console, I can see List<ShowingLocation>. In fact if I add this code:
_elementsHere.insert(0, Text('hello'));
I receive error that Text isn't a subtype of ShowingLocation, despite it's a Widget.
I want _elementsHere as List<Widget> instead of List<ShowingLocation>.
This can be solved by specifying the object type in the generics field of the map function. Since you're not specifying the type, it's being assumed to be an iterable of ShowingLocation.
Do this instead:
List<Widget> _elementsHere = _locationsRegister
.map<Widget>((e) => ShowingLocation(
num: e.num,
name: e.name,
icon: e.icon,
))
.toList();
Another option is as keyword.
List<Widget> _elementsHere = _locationsRegister
.map((e) => (ShowingLocation(
num: e.num,
name: e.name,
icon: e.icon,
) as Widget))
.toList();

Filtering Rows in F#

I have a code where I have the following frame and filter rows as follows:
let dfff=
[ "year" => series [ 1 => 1990.0; 2 => 1991.00; 3 => 1992.0; 4 => 1993.0]
"gold" => series [ 1 => 10.0; 2 => 10.00; 3 => 15.0; 4 => 20.0]
"silver" => series [ 1 => 20.0; 2 => 30.00; 3 => 45.0; 4 => 55.0] ]
|> frame
let dfff2 = dfff |> Frame.filterRows (fun key row -> row?year <= 1992.0 )
Why do I have to write key in
Frame.filterRows (fun key row -> row?year <= 1992.0)
if my function only depends on row? What role does key play here? I will appreciate if anybody could explain me the logic. Thanks!
In Deedle, frames have row keys and column keys. In your case, you have Frame<int, string> meaning that the row keys are integers (just numbers) and column keys are strings (column names) - but you might also have dates or other more interesting things as row keys.
The filterRows function gives you the row key together with row data. The key parameter is just the row key - in your case, this is (uninteresting) int index, but it might be e.g. useful date in other scenarios.
F# lets you write _ to explicitly ignore the value:
let dfff2 = dfff |> Frame.filterRows (fun _ row -> row?year <= 1992.0 )
In the Series module, we have Series.filter and Series.filterValues where the first one gives you key & value and the second one gives you just the value. So, we could follow the same pattern and add Frame.filterRowValues.
This would actually be quite easy, so if you want to contribute, please send a pull request with a change somewhere around here :-).

MVC EF select multiple joins

I have the following DB structure.
I want to make a select using Entity Framework. I want all my Categories that MAY have a CategoryText. If They have a CategoryText I also need to get the Language.
I searched and I couldn't find anything useful.
Here is my query that doesn't work:
var categoriesSQL = db.Categories
.Include(i => i.CategoryTexts.Select(s => s.Language)
.Where(w => w.Format == (string)Session["chosen_language"]));
var categories = categoriesSQL.ToList();
It throws:
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
Parameter name: path
I tried to solve this in a lot of ways and recomandations but I couldn't find a solution.
I want the select made in only one query.
Thank you!
Try this
var language = (string)Session["chosen_language"];
var categoriesSQL = db.Categories
.Include(i => i.CategoryTexts.Select(s => s.Language))
.Where(c =>
(from ct in c.CategoryTexts
from l in ct.Languages
select l.Format).Contains(language)
);
var categories = categoriesSQL.ToList();
OR
var language = (string)Session["chosen_language"];
var categoriesSQL = db.Categories
.Include(i => i.CategoryTexts.Select(s => s.Language))
.Where(c => c.CategoryText
.Any(ct => ct.Languages
.Any(l => l.Format == language)
)
);
var categories = categoriesSQL.ToList();

Where do I initialize backgrid in my Backbone/Rails app?

I have a Backbone.js app and am trying to integrate with Backgrid, but I am having trouble understanding where I should be calling new Backgrid. I tried calling it in my view after things get rendered but appending the grid doesn't work because things aren't actually rendered yet. Here is some code:
SpreadsheetIndex.js.coffee
D3.Views.SpreadsheetsIndex = Support.CompositeView.extend
initialize: (options) ->
this.tables = options.tables
this.resources = options.resources
_.bindAll(this, 'render')
render: ->
this.renderTemplate()
this.renderSpreadsheets()
resources = this.resources
this.tables.each (table) ->
subset = resources.subcollection
filter: (resource) ->
resource.escape('table_id') == table.escape('id')
grid = new Backgrid.Grid
columns: table.attributes.columns
collection: subset
$("#"+table.escape('id')).append(grid.render().$el);
return this
renderTemplate: ->
this.$el.html(JST['spreadsheets/index']({ spreadsheets: this.tables }))
renderSpreadsheets: ->
self = this
self.$('tbody').empty();
spreadsheets/index.jst.ejs
<% spreadsheets.each(function(spreadsheet) { %>
<h4><%= spreadsheet.escape('name')%></h4>
<div id='<%= spreadsheet.escape('id') %>'></div>
<% }) %>
The issue is that the $("#"+table.escape('id')) selector does not select anything because the template hasn't rendered yet. It feels like I'm putting this in the wrong place. What am I doing wrong?
I'd guess that you want to use the view's #$ method to instead of $ to localize the selector to the view's el:
this.tables.each (table) =>
#...
#$("#"+table.escape('id')).append(grid.render().$el);
Note that -> has become => (to get the right #/this) and it now uses #$ instead of $.
While I'm here, you can do a couple other things to make your code more ideomatic:
Say class D3.Views.SpreadsheetsIndex extends Support.CompositeView instead of the JavaScripty D3.Views.SpreadsheetsIndex = Support.CompositeView.extend.
Use # instead of this, for example #tables = options.table rather than this.tables = options.table.
You can use string interpolation instead of + if you think it is cleaner:
#$("##{table.escape('id')}")
You rarely need bindAll, instead of _.bindAll(this, 'render') you could define render as render: => to get the binding to happen automatically.
You rarely need the var self = this trick in CoffeeScript, you can usually use a => instead. And you don't need either one here:
renderSpreadsheets: ->
self = this
self.$('tbody').empty();
you can just renderSpreadsheets: -> #$('tbody').empty()

magento using join in grid.php prepareCollection

Can someone tell me how to make a join within magento
Here is the problem:
<?//kleurtjes
$collection= Mage::getModel('faq/faq')->getCollection();
$collection->getSelect()->join(array('faqcat' => $this->getTable('faqcat/faqcat')), 'faqcat.faqcat_id=faq.faqcat_id' , array('faqcat.*'));
?>
i am trying to make a join with the table faqcat where i use the key faqcat_id .
futher i want that faqcat.name + faq.faq_id are being selected cos these are the values i want to use in colums.
<?
protected function _prepareColumns()
{
$this->addColumn('faq_id', array(
'header' => Mage::helper('faq')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'faq_id',
));
$this->addColumn('name', array(
'header' => Mage::helper('faqcat')->__('Titel'),
'align' =>'left',
'index' => 'name',
));
}
?>
after trying 1000 combinations i dont know what to do anymore ... who is willing to help me
this is the complete function:
<?
protected function _prepareCollection()
{
$collection= Mage::getModel('faq/faq')->getCollection();
//$collection->getSelect()->join(array('faqcat' => $this->getTable('faqcat/faqcat')), 'faqcat.faqcat_id=faq.faqcat_id' , array('faqcat.*'));
$id = Mage::getModel('customer/session')->getCustomer()->getId();
$this->setCollection($collection);
// }
return parent::_prepareCollection();
}
?>
just to be clear this is the sql i want to have , but then the magento way
<?//kleurtjes
SELECT faq.faq_id as id, faqcat_name as name
FROM faq
JOIN faqcat
USING ('faqcat_id')
?>
Try this:
$collection->getSelect()
->join($this->getTable('faqcat/faqcat'), "faqcat.faqcat_id = main_table.faqcat_id", array(faqcat.*));
You can see the sql that will actually be run to fetch the collection by:
Mage::log($collection->getSelect()->__toString());
The Varien_Db_Select class is based on Zend_Db_Select, so the Zend documentation is a good reference.
i have just started developing magento extension (loving it) and this is the 2nd part in it where i have to show a grid from two tables. (whew).
but its not that easy after surfing internet a lot i achieved mine result by doing this.
$collection = Mage::getModel('linkdirectory/linkdirectory')->getCollection();
$resource = Mage::getSingleton('core/resource');
$collection->getSelect()
->join(
array('lk'=>$resource->getTableName('linkdirectory/linkcategory')),
'lk.cat_id = main_table.cat_id',
array('lk.cat_title','lk.cat_id')
);
/* mine was showing this */
/SELECT main_table., lk.cat_title, lk.cat_id FROM linkdirectory AS main_table INNER JOIN linkcategory AS lk ON lk.cat_id = main_table.cat_id*/
/* to print the current query */
$collection->printlogquery(true);exit;

Resources