I have id from the city that is supposed to be selected in dropdown list, but I can`t manage to preselect it. Should I select it from directive or is there any other way?
<select ng-model="cityId" ng-options="city.name for city in cities"></select>
Edit your ng-options to this:
city.id as city.name for city in cities
if you fetch the cities and don't know the ID's
you could say in your javascript success function (which returns the cities):
$scope.cityId = the_cities[0].ID
to set the first as selected
Else you could just say:
$scope.cityId = 1; //or anything that exists
You would need to use select as part for that, provided id is respective property on city object you would do:
ng-options="city.id as city.name for city in cities"
Otherwise you need to provide same object reference (of city object in the array) as the ng-model (if not using track-by).
When using track-by you would do:
ng-options="city.name for city in cities track by city.id"
and set the model as:
$scope.cityId = {id:'CITY1'};
When track by is used you do not need to worry about object references and it will actually have the value property of options reflecting exact id (unlike select as which keeps an internal map with index). This is helpful when doing form posts. But you should be careful not to mix it with select as since both are meant for different purposes and the implementation conflicts each other.
Related
So, starting with the following query, I can pass user input to the Geocode API and return a json object/response with the locations details.
http://maps.googleapis.com/maps/api/geocode/json?address=10010
My problem is I have the following query with component filters with the country set to the US (United States). However, if you enter in a zipcode like this which is returning an area in Russia it still renders the map and sets the marker for the users current location.
http://maps.googleapis.com/maps/api/geocode/json?address=16721**&components=country:US**&sensor=false
Do I need to check the short_name within the returned object in a simple if statement and choose whether to issue a map request or not?
I thought component filters would restrict the user to search within the country specified? Then, return ZERO_RESULTS if there is not a match.
Any input, feedback is welcomed. Thanks!
Remove stars from from country name:
http://maps.googleapis.com/maps/api/geocode/json?address=16721**&sensor=false&components=country:US
I have a nested repeated structure, the repeated structure is of variable length. For example, it could be a person object with a repeated structure that holds cities the person has lived in. I'd like to find the last item in that list say to find current city person lives in. Is there an easy way to do this, I tried looking around jsonpath functions but I'm not sure how to use it with "within". Any help please?
1) You can use LAST and WITHIN
SELECT
FIRST(cell.value) within record ,
LAST(cell.value) within record
FROM [publicdata:samples.trigrams]
where ngram = "! ! That"
2) or if you want something more advanced you can use POSITION
POSITION(field) - Returns the one-based, sequential position of field within a set of repeated fields.
You can check the samples from trigrams (click on Details to see the unflatten schema)
https://bigquery.cloud.google.com/table/publicdata:samples.trigrams?pli=1
And when you run POSITION, you get the ordering of that field.
SELECT
ngram,
cell.value,
position(cell.volume_count) as pos,
FROM [publicdata:samples.trigrams]
where ngram = "! ! That"
Now that you have the position, you can query for last one.
I'm trying to define a LOV with Universe Designer that when used in a #Prompt shows the user the item description, but gives back the corresponding item key as result of user selection.
e.g. From a dimension table of countries with two columns as COUNTRY_ISO and COUNTRY_NAME, I would like to show COUNTRY_NAME values to user with #prompt, but get back the corresponding COUNTRY_ISO as return value of #prompt.
This is possible using Index Awareness. I'll describe the solution using the sample "Island Resorts Marketing" universe, but the concept should map to your specific need.
For this example, we'll create a prompt on the "Country" object in the "Resort" class. The prompt will display the country names, but the condition will apply to the country_id field.
First, we need to identify the keys. On the Keys tab of the Resort\Country object, add a new Primary Key using Resort_Country.country_id as the source:
(in your case, you'll do this on the COUNTRY_NAME object, using COUNTRY_ISO as the primary key)
Next, we create the predefined condition that will include the prompt. Create a new Predefined Condition, named "Select country", with the following definition:
Resort_Country.country_id = #Prompt('Choose a country','A','Resort\Country',Mono,primary_key)
What we're doing is is applying the condition to the ID field (resort_country.country_id), but using the country name (the Country object) as the source. Note the "primary_key" parameter -- this tells BO to use the PK from the referenced object.
Now to test. Create a WebI report and select the "Select country" filter along with a field to display. I chose Service Line:
I run the report and am presented with a list of country names. I choose France, and I get a list of the Service Lines associated with France. The SQL generated by this query, reflecting my prompt selection, is:
SELECT
Service_Line.service_line
FROM
Service_Line,
Country Resort_Country,
Resort
WHERE
( Resort_Country.country_id=Resort.country_id )
AND ( Resort.resort_id=Service_Line.resort_id )
AND ( Resort_Country.country_id = 2 )
Note the very last line, which shows that the condition is applied using the ID, even though I selected the country name "France".
References:
- XI3.1 Designer Guide #Prompt info, starting on page 520
- Dave's blog on Index Awareness
- Dave's blog on Index Awareness with prompts
Suppose you have a complete user entry with al details like department, company name, job title, some custom fields, etc.
How should we delete a field or leave it blank; for example, I if I try to leave blank company name to delete it, I get a "Cannot call method "setCompanyName" of null, so how should deletion of this information should be managed?
With single value fields like Department, CompanyName etc you can set the value to an empty string (not null) to remove the existing value. For example:
profile.setCompanyName('');
For custom fields, use .deleteCustomeField() and fields for which there can be multiple instances use the provided delete methods like .deletePhoneField(). Use them like this:
var phones = profile.getPhones();
for (var i in phones) {
phones[i].deletePhoneField();
}
The ProfilesApp Tests script has examples of all these in unit tests.
Say I have an entity Customer which has relationship with city, order etc. Now when I am adding a customer object, should I assign customer.cityid, or customer.city? From the form I get cityid from a dropdown, so to assign the city object, I will have to make a query using id selected.
If you need the City object populated, then get the City and set .City.
If you don't need the City object and are just saving and moving on, setting .CityId without getting the city object will save you the select query fetching it.
In either case, the next time the object loads, City will be available. (Both methods save the same City column in the database unless you have something strange/non-default setup).