Map().set() does not add element in Collection, using NativeScript - nativescript

I recently have had a problem when coding using NativeScript.
I tried using Map() object as a Collection, but its set() method seems not to work.
I use the following snippet :
var r = new Map();
r.set("one", "two");
console.dir(r);
It however outputs an empty Map(), and I do not know why...
For your convenience, here is a link to a NativeScript PlayGround: https://play.nativescript.org/?template=play-ng&id=evhIxX&v=2
I inserted the snippet inside home.components.ts
Thanks alot!
LMy

Actually it works, if you try r.get("one") then you will see two in console.
May be console.dir does not handle Map as expected. You may report that in the GitHub project.

Related

How to convert a promise in protractor to a string

I am a bit new to Protractor and Jasmine, and I am trying to check if a list of elements that I have fetched using getText() contains a particular element:
Consider the following elements
var productNameElements = element.all(by.css('.table-row')).getText();
elementToBeSearched = element(by.css('.table-row .table-row-child(1)')).getText();
Now since both the variables above would return a promise, therefore by doing:
expect(productNameElements).to.eventually.contain(elementToBeSearched);
would fail, and it does fail.
Therefore, I believe that converting elementToBeSearched into a string would be beneficial and would make my life easier. Please suggest a solution on how can I convert a getText() promise to a string. Thanks
Lets say that the element is ele. So the way you should resolve the promise is-
ele.getText().then(function(str){
expect(someOtherElement.getText()).toBe(str);
})
The .then resolves the promise for you. You can confirm the string by puting a console.log(str)before you compare with expect.
PS: The promise inside the expect parenthesis is automatically resolved.
What i did was mostly similar:
productNameElements = element.all(by.css('.table-row')).getText().then(function(name) {
expect(productNameElements).to.eventually.contain(name);
});
This seems to have done the trick for me as I also checked the value of 'name' using console logging
Below code works for me:
let txt = (await elementToBeSearched.then()).toString();

insertNewChild is not a function in DHTML Tree grid Pro

I want to access child data from server when we append parent. Now I am using
mygrid.attachEvent("onOpenStart", getSubElements );
When I am using getSubElements, this method then it is showing an error: inserNewChild is not a function.
I am using this line, please review this and let me know where I am doing wrong.
mygrid.insertNewChild("a0J9000000TTdLtEAL","a0J9000000TTdKz","CLASS.000010",0,0,0,0,"");
Please note that the insertNewChild() is the method of the dhtmlxTree, and won't work in dhtmlxTreegrid.
http://docs.dhtmlx.com/api__dhtmlxtree_insertnewchild.html
You may use the addRow() method:
http://docs.dhtmlx.com/api__link__dhtmlxtreegrid_addrow.html
Also please try to use the onOpenEnd event instead of onOpenStart:
http://docs.dhtmlx.com/api__dhtmlxtreegrid_onopenend_event.html

mvc3 dapper parameter issue

I have dapper working correctly, but it is unsecure as in I haven't been using parameters, how can I best turn my dapper variables into parameters for instance this is the unparameterized code that I had that worked..
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location="+ myplace).FirstOrDefault();
myplace is a textbox that users put information on, now when I tried to parameterized that code like
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location='#location'", new {location = myplace}).FirstOrDefault();
I get absolutely no returns back, yet no error messages. What can I be missing here or whats the best way to parameterized variables.
You do not need to place the single quotes around the parameter. Hope this helps.
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location=#location", new {location = myplace}).FirstOrDefault();

Can't make MVC4 WebApi include null fields in JSON

I'm trying to serialize objects as JSON with MVC4 WebAPI (RTM - just installed VS2012 RTM today but was having this problem yesterday in the RC) and I'd like for all nulls to be rendered in the JSON output.
Like this:
[{"Id": 1, "PropertyThatMightBeNull": null},{"Id":2, "PropertyThatMightBeNull": null}]
But what Im getting is
[{"Id":1},{"Id":2}]
I've found this Q/A WebApi doesnt serialize null fields but the answer either doesn't work for me or I'm failing to grasp where to put the answer.
Here's what I've tried:
In Global.asax.cs's Application_Start, I added:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
json.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
This doesn't (seem to) error and seems to actually execute based on looking at the next thing I tried.
In a controller method (in a subclass of ApiController), added:
base.Configuration.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
base.Configuration.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
I say #1 executed because both values in #2 were already set before those lines ran as I stepped through.
In a desperation move (because I REALLY don't want to decorate every property of every object) I tried adding this attrib to a property that was null and absent:
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include,
NullValueHandling = NullValueHandling.Include)]
All three produce the same JSON with null properties omitted.
Additional notes:
Running locally in IIS (tried built in too), Windows 7, VS2012 RTM.
Controller methods return List -- tried IEnumerable too
The objects I'm trying to serialize are pocos.
This won't work:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
But this does:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings()
{
NullValueHandling = Newtonsoft.Json.NullValueHandling.Include
};
For some odd reason the Newtonsoft.Json.JsonFormatter ignore assigments to the propreties os SerializerSettings.
In order to make your setting work create new instance of .SerializerSettings as shown below:
config.Formatters.JsonFormatter.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings
{
DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include,
NullValueHandling = Newtonsoft.Json.NullValueHandling.Include,
};
I finally came across this http://forums.asp.net/t/1824580.aspx/1?Serializing+to+JSON+Nullable+Date+gets+ommitted+using+Json+NET+and+Web+API+despite+specifying+NullValueHandling which describes what I was experiencing as a bug in the beta that was fixed for the RTM.
Though I had installed VS2012 RTM, my project was still using all the nuget packages that the beta came with. So I nugetted (nugot?) updates for everything and all is now well (using #1 from my question). Though I'm feeling silly for having burned half a day.
When I saw this answer I was upset because I was already doing this and yet my problem still existed. My problem rooted back to the fact that my object implemented an interface that included a nullable type, so, I had a contract stating if you want to implement me you have to have one of these, and a serializer saying if one of those is null don't include it. BOOM!

Cache won't work in Appcelerator

Titanium SDK version: 1.6.
iPhone SDK version: 4.2
I am trying out the cache snippet found on the Appcelerator forum but I get an error: [ERROR] Script Error = Can't find variable: utils at cache.js (line 9).
I put this one (http://pastie.org/1541768) in a file called cache.js and implemented the code from this one (http://pastie.org/pastes/1541787) in the calling script, but I get the error.
What is wrong? I copied the code exactly.
Your problems is whilst the first pastie defines utils.httpcache. The variable utils is not defined outside of this function closure (because it is not defined anywhere in global namespace). As below shows.
(function() {
utils.httpcache = {
};
})();
To make it all work in this instance add the following code to the top of your cache.js file.
var utils = {};
This declares the utils variable in global namespace. Then when the function closure is executed below it will add utils.httpcache to the utils object.
The problem is actually not specific to Appcelerator and is just a simple JavaScript bug. Checkout Douglas Crockfords book, JavaScript the Good Parts. Reading it will literally make you a more awesome JavaScript developer.
You can't use utils.httpcache.getFromCache(url) until you add this to your code:
var utils = {};
That's because how the author created his function, it's called JavaScript module pattern and it's generally used to structure the code.
I seem to lose this value "value.httpCacheExpire = expireTime;" when the code does the "Titanium.App.Properties.setString(key,JSON.stringify(value));" so when I get it back using the getString method, there's no longer the "value.httpCacheExpire.
Anyone else have this issue? Am I missing something to get this working?

Resources