What is the right way to introspect a qooxdoo object? - qooxdoo

I want to list all members of a qooxdoo object. I found a way to do it, but I assume there must be a cleaner way?
for (var key in obj) {
if (key.startsWith('$$user_')) {
msg += 'name='+key.substring(7)+' = '+obj[key]+' [type='+typeof(obj[key])+']';
}
}

Assuming it is properties you are interested in, you can use
var classProperties = qx.util.PropertyUtil.getAllProperties(obj.constructor);
for(var propertyName in classProperties) {
...
}
http://tinyurl.com/c4b2l5m

Related

How to add an item to a custom index in Sitecore programmatically?

I have created my custom Index in Sitecore with FlatDataCrawler.
Now I am going to add new item inherited from AbstractIndexable to my index.
private void Test() {
var newItem = new ContactIndexable {
Number = new System.Random().Next(500, 10000),
MyField = "Item from IMPORTER"
};
var index = ContentSearchManager.GetIndex("my_index");
using (var ctx = index.CreateUpdateContext()) {
//This line doesn't work:
ctx.Index.Operations.Add(newItem, index.CreateUpdateContext(), index.Configuration);
index.Refresh(newItem);
}
}
Calling this code causes that only the GetItemsToIndex method is called in my custom crawler, but the element is not added to the Index.
So, how can I add a new item to my custom index from code?
This method works correctly and a new element is added to the index:
protected override IEnumerable<ContactIndexable> GetItemsToIndex() {
List<ContactIndexable> items = new List<ContactIndexable>() {
new ContactIndexable()
{
MyField = "Created in crawler"
}
};
return items;
}
You're really close. You have to queue up the context first and then add and commit.
using (var solr = ContentSearchManager.GetIndex("my_index'))
{
var ctx = solr.CreateUpdateContext();
solr.Operations.Add(newItem, ctx, solr.Configuration);
ctx.Commit();
}
Since this is using SolrNet under the hood, all operations against Solr have to be committed.

Error when bind values into a nested object

Problem when binding values into a nested object
I want to add data to the following object structure.
Company {
stat {
internalData {
value = 35
}
}
}
I have used the below code
Company.stat.internalData["value"] = 35;
When I used the above code I got the error as internalData is undefined.
Could someone kindly help me. Thanks inadvance.
It seems that you have already created the following object:
let Company = {
stat: {
}
}
As you can see, internalData is sure not defined. You can't access it's fields using internalData["value"]. You need to create it first like this:
Company.stat.internalData = {};
And then define its property called value:
Company.stat.internalData["value"] = 35;
Company.stat.internalData.value = 35; would work too.
Or, you can create the entire object with just one expression:
let Company = {
stat: {
internalData: {
value: 35
}
}
}
Issue here is you are trying to access the property before the object Company is defined. So you need to define something like this before setting the value,
Company = {};
Company.stat = {};
Company.stat.internalData["value"] = 35;

How do I filter by 'keywords' with angular.js?

I'm trying to create a robust filtering system with basic HTML & angular.js, so far with the help of a few kind people on here, I've ended up with this:
http://codepen.io/liamtarpey/pen/jfvDK
It works fine, the only issue is if you type something backwards, for example if the user searches for: 'taco mexican' or even 'mexican taco', you'd get no results at all.
Is there a way to use the filter as more of a keyword filter rather than a string filter?
You will have to iterate through every property for every word in the search term. This works:
$scope.search = function(user) {
var match = true;
$scope.query.split(" ").forEach(function(word) {
if (match === true) {
var wordMatch = false;
for (var prop in user) {
if (user.hasOwnProperty(prop)) {
if(user[prop].toLowerCase().indexOf(word.toLowerCase()) > -1) wordMatch = true;
}
}
}
match = wordMatch;
});
return match
}

How to declare array with custom indices, in Unity JavaScript?

I'm looking for a way to store variables of same type in an array, and access them by their names. Like in PHP you do:
$array = array();
$array['first member']=$var1;
$array['another member']=$var2;
// so on
I want to do a similar thing in Unity3D's JavaScript. I have AudioClip variables, currently used like this:
#pragma strict
var Audio_Goal:AudioClip;
var Audio_Miss:AudioClip;
var Audio_Saved:AudioClip;
function PlaySound_Goal()
{
audio.PlayOneShot(Audio_Goal);
}
function PlaySound_Miss()
{
audio.PlayOneShot(Audio_Miss);
}
of course this requires one function per audioclip, which is ugly.
I want to do it like this:
function PlayAudio(audioname:String)
{
audio.PlayOneShot(AudioArray[audioname]);
}
How can I do this?
You need to use something like a dictionary:
#pragma strict
import System.Collections.Generic;
var AudioArray = new Dictionary.<string,AudioClip >();
// add to dict
AudioArray["one"] = AudioClip.Create(/**/); //see AudioClip.Create(...) for arguments
// play from dict
audio.clip = AudioArray["one"];
audio.Play();
You can do something like:
var myAudioClips: AudioClip[];
function Start() {
// Your stuff...
}
function PlayAudio(audioname:String)
{
for (var myClip in myAudioClips) {
if (audioname.Equals(myClip.name)) {
audio.PlayOneShot(myClip);
}
}
}
And then add all of your clips in the array by dragging them using the editor.
You should be able to use Enumerable.Zip>, but because it's not available in UnityScript, I think this is the best you can do:
var names : List.<String>;
var clips : List.<AudioClip>;
var keyFunc = function(kvp : KeyValuePair.<String, AudioClip>) kvp.Key;
var valueFunc = function(kvp : KeyValuePair.<String, AudioClip>) kvp.Value;
var dictionary = names.Select(
function(name, index) new KeyValuePair.<String, AudioClip>(name, clips[index])
).ToDictionary(keyFunc, valueFunc);
I don't know why you need to store the Funcs. This code compiles, but won't run:
var dictionary = names.Select(
function(name, index) new KeyValuePair.<String, AudioClip>(name, clips[index])
).ToDictionary(function(kvp) kvp.Key, function(kvp) kvp.Value);
Report it as a bug if you want. I don't want to, because I don't think the devs need to waste any more time on this language.

Retrieve only one item with MVVM light in Silverlight

To grab some content from a WCF Data Service into my View Model is straight forward:
public const string RequestsPropertyName = "Requests";
private DataServiceCollection<Request> _requests = null;
public DataServiceCollection<Request> Requests
{
get { return _requests; }
set
{
if (_requests == value) { return; }
var oldValue = _requests;
_requests = value;
RaisePropertyChanged(RequestsPropertyName, oldValue, value, true);
}
}
and then
Requests.LoadAsync(query);
But what if I have a property which is not a collection?
public const string RequestDetailsPropertyName = "RequestDetails";
private Request _requestDetails = null;
public Request RequestDetails
{
get { return _requestDetails; }
and so on.
Where do I get the 'LoadAsync(query)' method from?
Thank you,
Ueli
This is a pretty simple thing to do. You just need to use the DomainContext in your application. This is where you create your query from, then apply the result to your property.
Here is an example of what this might look like in your code:
void LoadRequest(int requstID)
{
var query = workContext.GetRequestByIDQuery(requestID);
workContext.Load(query, lo =>
{
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
if (lo.HasError)
throw lo.Error;
else
RequestDetails = lo.Entities.Single();
});
}, null);
}
In this example, the workContext object is the DomainContext. The query is an specific version on the server - you can also just contruct the query client side with:
.Where(r => r.RequestID == requestID)
After the async call, it thows any errors that occurred from the async call, and then returns the only entity returned. If you get more than 1 entity, you might use .First() instead.
If this is not enough to get you going, let me know and I can explain further.

Resources