Filtering an array....of hotels - sabre

let thisHotel: number = this.$("#hotelsList").val(); // the selected hotel Id value for the one I want..
let hotels2 = this.getModel().get("hotels"); // all the hotels
I have the selected hotel I want in my massive array...
I can see the hotels in the debug by doing specifically
console.log(hotels2.hotels);
thisHotel currently = 4 which is the value of one of the hotels.
Loop through hotels2 then the object is under hotels then the specific Id is 4.
I need to get the entire object for the specific hotel where Id = 4
I know there are a number of ways to do this. Some people may use Javascript and some people may use Jquery. What would you do?
Every example I see is always referring to a simple array with one or two values.
This is a more complex object.. I guess these are just the way it works in real life examples.
I'm a newbie so please help me get my bearings ...

I did it this way... if you have better suggestions let me know please...
let foundHotel;
//console.log("Hotel Count=" + hotels2.hotels.length);
for (var i = 0; i < hotels2.hotels.length; i++) {
var x = hotels2.hotels[i];
console.log("Looping thru " + x.Id + " checking for " + thisHotel);
if (x.Id == thisHotel) {
console.log("Match on " + x.HotelInformation.Name);
foundHotel = hotels2.hotels[i];
break;
}
}
console.log(foundHotel);
Then I use jquery to prepopulate my form with the info about the selected hotel....
$("#HotelName").val(foundHotel.HotelInformation.Name);
$("#HotelChainCode").val(foundHotel.HotelInformation.ChainCode);

Related

AppMaker - Navigate to Last Page on Table

Scenario:
I have a calculated SQL that returns 100 results.
Added a table (from this calculated SQL) and limited the size of the page by 25 results.
This will generate 4 pages.
Pager form AppMaker works well (navigates between pages) but i need a button that navigates directly from page 1 to the page 4.
is this possible?
Anyone got a solution for this?
Regards
If you need to know how many entries your table has (in your case it's seems fixed to 100, but maybe it could grow), you can still do what you want:
E.g. say your table on YOURPAGE depends on a datasource called Customers.
Create a new Data item called CustomerCount, with just one field, called Count (integer).
Its data source would be a sql query script:
Select count(CustomerName) as Count from Customers
on the page you are having the table on, add a custom property (say called
Count of type integer)
In the page attach event, set the property asynchronously with this custom action:
app.datasources.CustomerCount.load(function() {
app.pages.YOURPAGE.properties.Count = app.datasources.CustomerCount.count;
app.datasources.Customers.query.pageIndex = #properties.Count / 25;
app.datasources.Customers.datasource.load();
});
I tried similar things successfully in the past.
Found a solution for this:
ServerScript:
function CandidateCountRows() {
var query = app.models.candidate.newQuery();
var records = query.run();
console.log("Number of records: " + records.length);
return records.length;
}
in the button code:
var psize = widget.datasource.query.pageSize;
var pidx = widget.datasource.query.pageIndex;
var posicao = psize * pidx;
var nreg = posicao;
google.script.run.withSuccessHandler(function(Xresult) {
nreg = Xresult;
console.log('position: ' + posicao);
console.log('nreg: ' + nreg);
console.log('psize: ' + psize);
console.log('pidx: ' + pidx);
var i;
for (i = pidx; i < (nreg/psize); i++) {
widget.datasource.nextPage();
}
widget.datasource.selectIndex(1);
}).CandidateCountRows();
This will allow to navigate to last page.
If you know for a fact that your query always returns 100 records and that your page size will always be 25 records then the simplest approach is to make sure your button is tied to the same datasource and attach the following onClick event:
widget.datasource.query.pageIndex = 4;
widget.datasource.load();

Xamarin grid, column and row amounts

Hi im relatively new to c# code and i was wondering if there is any way to get the amount of columns and rows in a grid and store that amount in a variable
Something like:
var columnamount = grid.columnamount;
But i could not find anything that works
Thanks
You can use the following code to get a count of the columns and rows directly via the ColumnDefinitions and RowDefinitions properties. No need to enumerate the children of the grid because you may not have views in every column/row.
var columnCount = grid.ColumnDefintions.Count;
var rowCount = grid.RowDefinitions.Count;
For reference the documentation.
You might be able to do it this way, purely based on what I see in the docs:
var countColumns = grid.Children.Where( c => c.Column).Max();
var countRows = grid.Children.Where( c => c.Row).Max();
But I'm not sure if you can access Row anf Column properties on the child element.
This is not the best way to check, I guess, but it's working (same thing for columns):
EDIT: nope, for columns it doesn't work
int GetRowsCount(Grid grid)
{
var item = grid.Children.FirstOrDefault();
return item != null ? Grid.GetRow(item) + 1 : 0;
}

Adobe Catalyst - 'Attribute Price' adding on to 'Sell Price' Issue

I have set a products sell price at £100. I have also created a 'Size' attribute at 'Large' £120.
But when I view the product and select 'Large' it prices up at £220 (adding the attribute and sell price together) when I'm wanting it at just the £120.
Any thoughts on why I'm getting this issue?
I believe Daut maybe talking about something else but I could be wrong.
When using attributes that you talk about, the price is calculated by default price plus the attribute price. This is why you see £220 as your total, as you have figured out.
In other words, your default price is £100. For your total to be £120, then your Large attribute would actually be £20. When it adds together, your total price will be £120.
When I use attributes with varying cost, I typically write my attribute as:
Large + [then BC inserts the price.]
On the BC App Store, there are a couple plugins (here and here) that assist with using Attributes. Their main purpose, from my understanding, is controling how the information is displayed to customers. I have no experience using either of these but it may help you.
Hi have created my own way around this issue in BC I also shared it on Business Catalyst Forum too. for select dropdown or radio buttons use the code bellow, you need to have a certain code ability to mend it together, it was quite done some time ago but if somebody interested on improving it to a cleaner way be welcome to share.
$(document).ready(function(){
StartDynamicPrice();
DoPriceChange();
});
var el_totalprice='#totalprice';
var el_totalprice_gst='#totalprice_gst';
//var el_attrselect='.catProdAttributeItem select';
// uncomment if you want radio as well
var el_attrselect='.catProdAttributeItem select, .catProdAttributeItem input';
var currencysymbol='£';
Number.prototype.toMoney=function(decimals, decimal_sep, thousands_sep){
var n = this,
c = isNaN(decimals) ? 2 : Math.abs(decimals),
d = decimal_sep || '.',
t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
sign = (n < 0) ? '-' : '',
i = parseInt(n = Math.abs(n).toFixed(c)) + '',
j = ((j = i.length) > 3) ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}
DoPriceChange=function(){
var selected='';
var newsubtotal=0;
$.each($(el_attrselect), function(i,e){
selected=$(e).children(':selected').text();
if (selected.indexOf(currencysymbol) != -1){
newsubtotal+=parseFloat(selected.substring(selected.indexOf(currencysymbol)+1));
};
});
newtotal=parseFloat($(el_totalprice).attr('base'))+parseFloat(newsubtotal);
newtotal_gst=newtotal+(newtotal*.10);
$(el_totalprice).html(currencysymbol+newtotal.toMoney());
$(el_totalprice_gst).html(currencysymbol+newtotal_gst.toMoney());
}
StartDynamicPrice=function(){
$(el_totalprice).attr('base',$(el_totalprice).html().replace(currencysymbol,'').replace(' ,','')); // set base price
$(el_attrselect).on('change',function(){
DoPriceChange();
})
}
/// END
Attributes in BC are add-ons. You cannot just get the attribute.
What you need is product grouping.
Group products together
You can create multiple products of the same type and group them together. A customer viewing one product can also see the available variations by selecting another product from the group.
Check how Grouping works in Business Catalyst
From the Actions menu, select Group Products Together.
Move the products from the left panel to the right, select a default product, and click Save.
Note: The default product is the only product that displays in a catalog. All other grouped products are available through the grouped product drop-down menu.

Game Maker Studio: Top 10 Highscores (Seriously)

I feel really dumb for having to post this, but I've been trying to achieve this for an entire week now and I'm getting nowhere!
I'm trying to create a highscore board. Top 10 scores, saved to an INI file. I have searched every single thing on the entire internet ever. I just do not get it.
So what I have tried is this...
I have a "load_room" setup. When this room loads, it runs this code:
ini_open('score.ini')
ini_write_real("Save","highscore_value(1)",highscore_value(1));
ini_write_string("Save","highscore_name(1)",highscore_name(1));
ini_close();
room_goto(room0);
Then when my character dies:
myName = get_string("Enter your name for the highscore list: ","Player1"); //if they enter nothing, "Player1" will get put on the list
highscore_add(myName,score);
ini_open('score.ini')
value1=ini_write_real("Save","highscore_value(1)",0);
name1=ini_write_string("Save","highscore_name(1)","n/a");
ini_close();
highscore_clear();
highscore_add(myName,score);
score = 0;
game_restart();
I'm not worried about including the code to display the scores as I'm checking the score.ini that the game creates for the real values added.
With this, I seem to be able to save ONE score, and that's all. I need to save 10. Again, I'm sorry for asking the same age-old question, but I'm really in need of help and hoping someone out there can assist!
Thanks so much,
Lee.
Why you use save in load_room instead load?
Why you clear the table after die?
You need to use loop for save each result.
For example, loading:
highscore_clear();
ini_open("score.ini");
for (var i=1; i<=10; i++)
{
var name = ini_read_string("Save", "name" + string(i), "");
var value = ini_read_real("Save", "value" + string(i), 0);
if value != 0
highscore_add(name, value);
}
ini_close();
room_goto(room0);
Die:
myName = get_string("Enter your name for the highscore list: ","Player1");
highscore_add(myName, score);
ini_open("score.ini");
for (var i=1; i<=10; i++)
{
ini_write_string("Save", "name" + string(i), highscore_name(i));
ini_write_string("Save", "value" + string(i), string(highscore_value(i)));
}
ini_close();
score = 0;
game_restart();
And few more things...
score = 0;
You need do it when game starts, so here it is unnecessary.
get_string("Enter your name for the highscore list: ","Player1");
Did you read note in help?
NOTE: THIS FUNCTION IS FOR DEBUG USE ONLY. Should you require this functionality in your final game, please use get_string_async.
I used ini_write_string(..., ..., string(...)); instead ini_write_real() because second case will save something like 1000.000000000, and first case will save just 1000.

Regarding to retrieve values inside the array

Hi
I am creating online quiz in asp.net c#. For that i have one form that displays testlist in dropdownlist & start button. After clicking 2nd form appears, 2nd form shows one label for question, radiobuttonlist for answers ,next & checkbox for review. I am creating array of random question ids in start button click event of the 1stform. when i click next button in 2nd form then next random question appears, i want array of questions those are checked for review. I used code for arrays of values ( eg.10101) 1 for true & 0 for false as follows but i want array of that question ids those are checked:
int[] a = (int[])Session["values"];//this is array of random question ids created in 1st form
int g;
if (chkmark.Checked == true)
{
g = 1;
}
else
{
g = 0;
}
int[] chkarray = new int[Convert.ToInt32(Session["Counter"]) - 1];
int[] temp1 = (int[])Session["arrofchk"];
int k, no;
if (temp1 == null)
no = 0;
else
no = temp.Length;
for (k = 0; k < no; k++)
{
chkarray[k] = temp1[k];
}
chkarray[j] = g;
Personally, i would use a Dictionary<int, bool> for this.
In the key of the dictionary, you can store the random Question ID, in the value of the pair, you can store the checked item state. It might take you more work now to refactor it, but I believe it will save you a lot of time in the end when you want to do more actions on your quiz items.
Using a dictionary - or at least a well chosen collection, I think it will be easier to get the right data back.
For your example, it can work only if the positions of both arrays are the same.
Dictionary<int, bool> quizAnswers = new Dictionary<int, bool>(); // <questionID, checked>
// Fill dictionary with questions and answers
for(int i=0;i<a.length;i++)
{
if(temp1.length > i) // Make sure we don't get an IndexOutOfBoundsException
{
quizAnswers.Add(a[i], temp1[i] == 1);
}
}
// Get Answered question in array ( LINQ )
int[] checkedAnswers = (from KeyValuePair<int, bool> pair in quizAnswers
where pair.Value == true
select pair.Key).ToArray<int>();
The reason I am using a Dictionary here, is because I personally think it's neater than having two separate arrays.
I believe you should implement a Dictionary in your quiz, in stead of those arrays. What if the array indexes don't match, or you want to dynamically add a question to a fixed size array, etc..
It's something to take into consideration. Hope I could help you out.

Resources