How to retriew values from NSDictionary? - ios6

I have a NSDictionary like this
`(
{
EmployeeCode = 7593;
InDate = "27/02/2013";
InTime = "08:11";
InTime2 = "00:00";
OutDate = "27/02/2013";
OutDate2 = "01/01/1901";
OutTime = "17:42";
OutTime2 = "00:00";
Present = 1;
}
)
Then I want to retriew values from this. So I putNSLog`
` NSLog(#"TESTING---------- %#",[dicDates valueForKey:#"OutDate"] );`
But the value displays with brackets
TESTING---------- (
"27/02/2013"
What is the reason for that. Plz help me
Thanks

You are calling a wrong method: instead of valueForKey: you need to call objectForKey:.
The valueForKey: method is for key-value coding, while objectForKey: is for retrieving objects through the associative mapping provided by NSDictionary.

Related

How to Push a JSON Array without the Index Keys?

I'm pretty new to JavaScript and need to create a JSON with number of keys and values (pushed into the variable newWord), without separating them. The thing is that I don't know what would be the length it in advenced (for that I am using a for loop to push each of the keys names and values):
let langName = document.querySelectorAll('.langName');
let langInput = document.querySelectorAll('.langInput');
let newWord = new Array()
for (let i = 0; i < langName.length; i++) {
let l = langName[i].value;
let w = langInput[i].value
newWord.push({[l]: w})
}
firebase.database().ref(`content/words/`).push(
newWord
)
So, my result right now is:
While my desired result would be:
Does anyone know how do I get rid of the indexes (0, 1) and push a string key with a string value?
Edit: I want the for loop to add to the same object in this array, instead of creating a new object inside of it.
Thanks! 😁
push is used to insert in a list in firebase database. Using set, you can store as key-value objects.
let langName = document.querySelectorAll('.langName');
let langInput = document.querySelectorAll('.langInput');
let newWord = {};
for (let i = 0; i < langName.length; i++) {
let l = langName[i].value;
let w = langInput[i].value
newWord[l] = w;
}
firebase.database().ref(`content/words/`).set(
newWord
)

How to check if a variable has certain symbols in React?

A new React developer here!
I'm trying to check if my array's dates have certain symbols in them e.g. "2019" or "-11-". I need to see if the array[i] doesn't have a date to add the inputted date to that slot. I could use !== undefined or isNaN, but it gives a number or empty as an error for some reason...
I've tried many different approaches, but I feel like this could be the way to go. Unless someone else figures out a better solution that is :D
Thanks for your time ^_^ Hopefully this is an easy fix that I just didn't notice!
/*
date = user-inputted date (XXXX-XX-XX)
dateData = {name, dates} in database ("name", "XXXX-XX-XX")
newOrder[] = dateData.dates, but rearranged to a correct order, no date
in the spot where "date" should be added
*/
let newOrder = [dateData.length + 1];
for (let i = 0; i < newOrder.length; i++) {
if (newOrder[i] /*solution here*/) {
newOrder[i] = moment(date).format("YYYY-MM-DD");
break;
}
}
// after this I'll update the database with async
When using moment, you could use the moment#isValid method to check if the current value is a valid date.
Although, I don't find it really clear what you are trying to achieve. Perhaps you can update your example with some data.
let newOrder = [dateData.length + 1];
for (let i = 0; i < newOrder.length; i++) {
const parsedDate = moment(date);
if (newOrder[i] && parsedDate.isValid()) {
newOrder[i] = parsedDate.format("YYYY-MM-DD");
break;
}
}
You can try this code.
"3-12-2019".indexOf('2019')
or
"3-12-2019".startsWith('2019') || "3-12-2019".endsWith('2019')
With moment you can get day, month and year.
var check = moment('2014-07-28', 'YYYY/MM/DD');
var month = check.format('M');
var day = check.format('D');
var year = check.format('YYYY');
console.log(month, day, year);
Considering this: dateData.dates is the Array where your dates are.
// Loops through the dates in the Array[]
dateData.dates.forEach(date => {
// Checks whether the date exists
// !date: if date = '' or null or any other falsy values will return true
if(!date){
date = moment(date).format("YYYY-MM-DD");
}
});

How to condition TYPO3 Solr sortBy

we have a TYPO3 project and use SOLR as search engine. i'm wondering how does a if-statement/conditional look like in the config files written in TypoScript?
TYPO3: 8.7
Apache Solr for TYPO3 - ES: 7.5.3
for example: we use
plugin.tx_solr.search.query.sortBy = data_datax_title_stringS asc
as sort setting for the following facet block:
plugin.tx_solr.search.faceting.facets {
but we only want that sorting if a certain part of the url query string is empty (q= or q=Searchtext)
so the sortBy should be applied if the query string looks like
http://localhost/?tx_solr%5Bq%5D=&L=0&id=2883
and should not be applied on
http://localhost/?tx_solr%5Bq%5D=Searchtext&L=0&id=2883
here is the actual block:
[globalVar = TSFE:id={$site.config.search_page_blasts}]
plugin.tx_solr.search.targetPage = {$site.config.search_page_blasts}
config.defaultGetVars {
tx_solr.filter.0 = result_type_filter:blast
}
plugin.tx_solr.search.query.sortBy = dynamic_field_A_stringS asc
plugin.tx_solr.search.faceting.facets {
facetX < lib.solr.facets.directBlast
facetX.field = dynamic_field_X_boolS
}
any help is highly appreciated
edit:
i found
plugin.tx_solr.search.query.getParameter = q
but this only defines the name for the query get-parameter in case another service needs a specific name. but i would need the value of this parameter and condition the sortBy by its value.
edit:
after some research im now at this state: the sort works if a query string is set - but not if its empty
[globalVar = GP:q = ""]
plugin.tx_solr.search.query.sortBy = wine_winery_title_stringS asc
[else]
plugin.tx_solr.search.query.sortBy =
[end]
[globalVar = TSFE:id={$site.config.search_page_wineries}]
plugin.tx_solr.search.targetPage = {$site.config.search_page_wineries}
config.defaultGetVars {
tx_solr.filter.0 = result_type_filter:winery
}
plugin.tx_solr.search.faceting.facets {
direct_sale < lib.solr.facets.directSale
direct_sale.field = winery_direct_sale_boolS
i dont really know how to format this the right way - nested conditions are not supported right?
We had a similiar use case and could not find a solution with existing featureset, so we ended up using a userfunction to check and redirect using the correct parameters.
Imo this is not the best way it should be solved though, so I am curious about other proposals.
# default sort by wine_winery_title_stringS
page.1558101700 = USER_INT
page.1558101700.userFunc = VENDOR\MyExt\UserFuncs\Solr->applyDefaultSorting
the userfunc could look like this:
/**
* #return void
*/
public function applyDefaultSorting()
{
$requestUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
$solrParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_solr');
$additionalParameterCharacter = '?';
if(strpos($requestUrl, '?') !== false){
$additionalParameterCharacter = '&';
}
// todo: get solr search parameter name from settings
if(isset($solrParameters['q']) === false || empty($solrParameters['q'])){
$redirectUri = $requestUrl . $additionalParameterCharacter . 'tx_solr[sort]=wine_winery_title_stringS+asc';
header('Location: '.$redirectUri);
}
}
hope it helps
[globalVar = GP:q = ""]
plugin.tx_solr.search.query.sortBy = wine_winery_title_stringS asc
[else]
plugin.tx_solr.search.query.sortBy =
[end]
but with [globalString = GP:q = /^$/]?
i ended up extending the outer condition and just having two blocks for that page - i feels redundant but works perfectly fine. the condition outside of the existing one was not working - and nested conditions are not possible. so here is the solution:
with globalString to use regex for comparison
[globalVar = TSFE:id={$site.config.search_page_x}] && [globalString = GP:tx_solr|q = /.+/]
and globalVar for an empty parameter
[globalVar = TSFE:id={$site.config.search_page_x}] && [globalVar = GP:tx_solr|q =]
hope i can save someone a little time researching - thanks to everyone for their input

Select single value from db

I need to select a single value from my db.
MyController.cs
using (var db = new MainDbContext())
{
var getPhoto = db.Users.Where(u => u.Name == User.Identity.Name).Select(u => u.Photo);
var materializePhoto = getPhoto.ToList();
var photo = materializePhoto[0];
}
I do this stuff in order to properly convert my value from IQueryable to String.
I've read about using 'FirstOrDefault', 'First', 'Default' select options (cause they return a string value, not IQuerable) but I think it isn't suitable for my case.
The question is: how can I make my code simplier and shorter?
P.S.: db.Users.Photo contains url's.
You need to add FirstOrDefault to your code
var getPhoto = db.Users.Where(u => u.Name == User.Identity.Name).Select(u => u.Photo).FirstOrDefault();
and yes, it will work.
You could do like this also
var photo = db.Users.Where(u => u.Name == User.Identity.Name).FirstOrDefault().Photo;
It will also return the first photo value
Please use FirstOrDefault() to select single record from db.

call extjs getById method with variable

I have a strange problem in my code. I want to get an item from store by its id. the value of itemId is 1 and I get null for firstItem.
var itemId = dragIdSplit[1];
var firstItem = me.getPStore().getById(itemId);
Then if I just call getById(1) the correct value will be returned. Can someone help me with this issue?
try below changes. you doing split so it's a string you have to convert it into integer.
var itemId = parseInt( dragIdSplit[1]);
var firstItem = me.getPStore().getById(itemId);

Resources