React Native - undefined is not an object(evaluating '_ref2.label') - react-native

I am using DropDownPicker in React-Native. I want DropDownPicker to be loaded by default for example first index. I want the 1st item of this.state.allAdresses Array to be loaded as defaultValue. But I am getting the error in the thread. What is the reason?
DropDownPicker
style = {{marginTop:10}}
items={this.state.allAdresses.map((item, index)=> ({label:item.firstname + " " + item.lastname + " " + item.address_1 + " " + item.address_2 + " " + item.city + " " + item.company + " " + item.postcode ,value:item.lastname, key: index}))}
placeholder="Adres seçiniz"
containerStyle={{height: 40, width:'100%',}}
defaultValue={this.state.allAdresses[1]}
onChangeItem={(itemValue, itemIndex) => this.changeAddress(itemIndex)}
/>

This is because you are referencing this.state.allAdresses[1] in defaultValue while defaultValue must be the value of the object you are trying to display as selected.
Here is one way to fix it
//Create an array from allAdresses you want to populate dropdownpicker with.
const items = this.state.allAdresses.map((item, index)=> ({label:item.firstname + " " +
item.lastname + " " + item.address_1 + " " + item.address_2 + " " + item.city + " " + item.company + " " +
item.postcode ,value:item.lastname, key: index}))
<DropDownPicker
style={{marginTop:10}}
//reference it like this
items={items}
placeholder="Adres seçiniz"
containerStyle={{height: 40, width:'100%',}}
//set 1 index
defaultValue={items[1].value}
onChangeItem={(itemValue, itemIndex) => this.changeAddress(itemIndex)}
/>

Related

Barcode CODE_128 using PrintHTML with Qz Tray

Good Day All,
Right now, i'm trying to print using HTML with Qz-Tray. Can i make a barcode on that template HTML. The Problem is, that HTML template is STRING so it can not be change it using Javascript and I'm Trying to use Libre Font 128 Font Family but still not working.
https://www.w3schools.com/howto/tryit.asp?font=Libre%20Barcode%20128 i want to use that library, in this
function printHTML() {
var config = getUpdatedConfig();
var colA = '<h2>* QZ Print Plugin HTML Printing *</h2>' +
'<span style="color: #F00;">Version:</span> ' + qzVersion + '<br/>' +
'<span style="color: #F00;">Visit:</span> https://qz.io/';
var colB = '<img src="' + getPath() + '/assets/img/image_sample.png">';
var printData = [
{
type: 'html',
format: 'plain',
data: '<html>' +
' <table style="font-family: monospace; border: 1px;">' +
' <tr style="height: 6cm;">' +
' <td valign="top">' + colA + '</td>' +
' <td valign="top">' + colB + '</td>' +
' </tr>' +
' </table>' +
'</html>'
}
];
qz.print(config, printData).catch(displayError);
}
or this https://barcode-coder.com/en/barcode-jquery-plugin-201.html

CRM 2013 refresh subgrid with fetchxml

In my scenario, i have a new entity called "new_relations" with 2 fields (account1 and account2) that are both lookups to accounts.
In my accounts form i want to display a grid containing any record with the current account, in any of the 2 lookups, that exists in "new_relations" entity.
I´ve created account A and account B; created 1 record in new_relations with new_relations.account1 = account A and new_relations.account2 = account B.
So, when i open account A or Account B i want to see the record created in new_relations.
I have the following code, unfortunately its only showing the record in Account´s A form in my subgrid...
Can anyone help?
function FilterRelacao(){
var relacoes = document.getElementById("Relacoes");
var account = Xrm.Page.data.entity.getId();
var accountname = Xrm.Page.data.entity.attributes.get("name").getValue();
if(relacoes==null){
setTimeout(function () { FilterRelacao(); }, 2000);
return;
}
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='new_relations'>" +
"<attribute name='new_type' />" +
"<attribute name='new_accountid1' />" +
"<attribute name='new_accountid2' />" +
"<attribute name='new_relationsid' />" +
"<order attribute='new_accountid1' descending='true' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<filter type='or'>" +
"<condition attribute='new_accountid1' operator='eq' uitype='account' uiname='" + accountname+ "' value='" + account + "' />" +
"<condition attribute='new_accountid2' operator='eq' uitype='account' uiname='" + accountname + "' value='" + account + "' />" +
"</filter></filter>" +
"</entity>" +
"</fetch>";
relacoes.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
relacoes.control.SetParameter("effectiveFetchXml", fetchXml); //set the fetch xml to the sub grid
relacoes.control.Refresh(); //refresh the sub grid using the new fetch xml
}
Your fetch XML looks correct to me. When you set up the subgrid did you set "Records" = "All Record Types" in the Data Source section? If you did not then the subgrid will append a condition to your fetchxml so that it returns only records related to the specific relationship that you specified.

kendo scheduler event template

Hi I would like to add a Kendo ToolTip inside the kendo Scheduler event template. When ever i add any Html helper it throws invalid template error. I might be missing some the syntax.Can anyone suggest the way to do it?
d.EventTemplate(
"<div style='height: auto !important;'>"+
"#=kendo.toString(start,'hh:mm')# #= kendo.toString(start,'tt')# #"+
"<span style='font-size:smaller'>#= PickStopName# </span> " +
"##(Html.Kendo().Tooltip().For('#Scheduler').Width(250)"+
".Content('# <div style='text-align:justify;'>" +
"<div>" +
"<h6> #= title# </h6>" +
"<h6> #= description# </h6>" +
"<h4> #= kendo.toString(start,'hh:mm')# </h4>" +
"</div>" +
"</div>)'#)#"+
"</div>"
);

DataMapper: Sorting results by association count (number of related objects)

Given are movies and actors in an m:n relation. What I want to do is retrieve a list of actors, ordered by the number of movies they played in.
class Movie
include DataMapper::Resource
property :id, Serial
property :title, String
has n, :actors, through: Resource
end
class Actor
include DataMapper::Resource
property :name, String, key: true
has n, :movies, through: Resource
end
In pseudo-DM what I want is this:
Actor.all order: [ :movies.count ]
I found another question about sorting by a single attribute of an association but this approach only worked for real properties. Any usable solution would be helpful. Thx!
Taking the answer by Sean Larkin as a starting point I ended up with something like this:
actors = repository(:default).adapter.select(
"SELECT actors.name, count(actor_movies.actor_name) AS count " +
"FROM actors " +
"JOIN actor_movies WHERE actors.name = actor_movies.actor_name " +
"GROUP BY actors.name " +
"ORDER BY count(actor_movies.actor_name) desc " +
"LIMIT 5;"
)
=> [
#<struct name="Samuel L. Jackson", count=66>,
#<struct name="Michael Caine", count=64>,
#<struct name="Robert De Niro", count=59>,
#<struct name="Harvey Keitel", count=58>,
#<struct name="Gene Hackman", count=57>
]
The documentation for DataMapper is little outdated and I struggled trying to accomplish the same thing that you were doing.
I instead used a direct MySQL query:
records = repository(:default).adapter.select(“SELECT * FROM actor ORDER BY count(movies) desc;”)
It is important to note that when you use the direct MySQL query, that a struct is returned rather than just a hash of the data. You will have to convert it into a hash manually if, say you are returning this data as JSON.
You could convert a struct to hash in Ruby 1.8-1.9 via:
actors = repository(:default).adapter.select( "SELECT actors.name, count(actor_movies.actor_name) AS count " + "FROM actors " + "JOIN actor_movies WHERE actors.name = actor_movies.actor_name " + "GROUP BY actors.name " + "ORDER BY count(actor_movies.actor_name) desc " + "LIMIT 5;" ).map{|struct| {:name => struct.name, :count => struct.count}}
In Ruby 2.0, they added to_h so you can use this:
actors = repository(:default).adapter.select( "SELECT actors.name, count(actor_movies.actor_name) AS count " + "FROM actors " + "JOIN actor_movies WHERE actors.name = actor_movies.actor_name " + "GROUP BY actors.name " + "ORDER BY count(actor_movies.actor_name) desc " + "LIMIT 5;" ).map(&:to_h)

how to use pagination query in fluent nhibernate

I want to use following query in fluent nHibernate:
_dataContext.Products
.Where(filterExpression)
.OrderBy(sortExpression + " " + sortDirection)
.Skip(pageIndex * pageSize)
.Take(pageSize);
in both Criteria and HQL use
.SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize)
LinqToNhibernate:
session.Query<Product>()
.Where(filterExpression)
.OrderBy(sortExpression + " " + sortDirection)
.Skip(pageIndex * pageSize)
.Take(pageSize);