setting hierarchical property for GXT's ComboBox.setDisplayField - combobox

i have a simple extension of a BaseModelData in a form of MyModel, and i can call new MyModel().getObj1().getObj2() to get to obj2's string value. i have a number of MyModel instances, so i would like to populate a ComboBox instance with an obj2 value from each MyModel instance. first, i called ComboBox.setDisplayField("obj1.obj2"), because using such hierarchical property approach works for TextField.setName() cases. then, i took a store which contains all MyModel instances, and set it to a ComboBox via setStore(). however, the combobox is empty. it looks as though setting the aforementioned property via ComboBox.setDisplayField() does not work the same way as it does for TextField.setName(). i tried using my own instance of ListModelPropertyEditor, but without success. so what are my alternatives?
thank you for your time!!!

I am not sure about accessing hierarchical data from ComboBox.setDisplayField() method, but can you can achieve it by adding a new method say getObj2() in MyModel class, which will essentially represent obj1.obj2.
public Obj2 getObj2() {
return getObj1().getObj2(); //with possible null checks
}
Now you can call ComboBox.setDisplayField("obj2") and get the work done.

Related

What is the difference between a model object queried by filter and an object queried by get() in Django?

I keep coming across this issue where I am trying to update a record using the update() method.
It always works when I query an object using filter.
my_dictionary = {"key":"Val","another":"Val"}
thing = Thing.objects.filter(pk=1)
thing[0].update(**my_dictionary) wrote it wrong in the original question.
thing.update(**my_dictionary)
When I query the object using get() it keeps telling me that the object has no method update()
my_dictionary = {"key":"Val","another":"Val"}
thing = Thing.objects.get(pk=1)
thing.update(**my_dictionary)
Isn't a model object the same in both cases? Why would one have an update method and the other one not? Any insight would be greatly appreciated.
The documentation is very explicit about this:
filter() will always give you a QuerySet, even if only a single object matches the query - in this case, it will be a QuerySet containing a single element.
If you know there is only one object that matches your query, you can use the get() method on a Manager which returns the object directly.
Your first snippet returns a QuerySet, which has an update method. The second snippet returns a model instance, which doesn't.
Note that you have not shown the exact code you are using: thing[0].update would give exactly the same error as the second snippet.
You're using QuerySet.update() and ModelInstance.save().
If you’re just updating a record and don’t need to do anything with the model object, the most efficient approach is to call update(), rather than loading the model object into memory. For example, instead of doing this:
e = Entry.objects.get(id=10)
e.comments_on = False
e.save()
...do this:
Entry.objects.filter(id=10).update(comments_on=False)

replace collection in a view

I want to replace a collection inside a view. I use the reset command like this:
var maColl=mContent.get(ici).get("svgParameterList");
msvgParameterListView.collection.reset(maColl);
A JSON.stringify gives this :
maColl
[{"id":"x","name":"x"},....{"id":"style","name":"style"}]
msvgParameterListView.collection
[[{"id":"x","name":"x"},....{"id":"style","name":"style"}]]
Now, i have my collection in an array, so when i render it return null value.
How to change array of collection into collection ?
In short, how to make msvgParameterListView.collection equal to maColl ?
Note the [[ ]] for the new collection.
Note maColl is a collection inside another collection.
If I understand correctly, you are trying to reset a collection with the models of another collection? collection.toJSON is your friend:
toJSON collection.toJSON()
Return an array containing the attributes hash of each model in the collection. This can be used to
serialize and persist the collection as a whole. The name of this
method is a bit confusing, because it conforms to JavaScript's JSON
API.
which could be applied like this
msvgParameterListView.collection.reset(maColl.toJSON());
Or if you want to keep a reference to the original models, pass maColl.models
msvgParameterListView.collection.reset(maColl.models);
Passing directly a collection to reset will only confuse Backbone.

How can I access to some model in Backbone collection

I have a collection of models:
city = new M.City
App.citiesList = new C.CitiesList model: city
App.citiesList.fetch()
How can I access to the model with id=15 for example?
I need something like App.citiesList.find(15).name(), where name() is model function
When I try to add function find to the collection it is incorrect.
When I try to iterate over App.citiesList.models - I see only one model or what it is.. I actually don't know.
Thanks a lot!
If App.citiesList is a Backbone collection then you'd want to use get:
get collection.get(id)
Get a model from a collection, specified by id.
So this would get you your model from the collection:
fifteen = App.citiesList.get 15
And if you wanted to call a method on it:
App.citiesList.get(15).name()
You'd probably want to make sure you got something back from App.citiesList.get 15 first though (unless you knew it was there of course). Since you're working in CoffeeScript you could use the existence operator like this:
name = App.citiesList.get(15)?.name()
#----------------------------^
to get 15's name or undefined in the name variable.
The find method on App.citiesList would be Underscore's find and that doesn't find an object with a particular ID.

Reuse my wpf Binding factory in other code

I've got user-definable columns for my data grid, which basically boils down to a
switch(column_title)
{
case "foo": binding = new Binding("Model.Fonz");
//etc.
}
and the binding gets applied to the column.
Now I need to dump to csv, with the configured columns. As it may be a different column set that being used in my ui and I definitely don't want two huge switch statements to maintain, I'd essentially like a function like this:
object GetBoundProperty(object o, System.Windows.Data.Binding binding)
I won't be surprised if its obnoxiously easy, but its outside the range of my .NET knowledge at the moment and I have little desire to parse the periods out of the binding and search through reflection unless I totally have to. Thanks!
Let me suggest something else. I just don't like idea with getting data from model through databindings when you can get it directly from model... Rather than having two big switches you could create one class per column, that will handle your data requests. In pseudocode it will look like this:
ColumnData fonzColumnData = ColumnsFactory.Create(columnTitle);
// for bindings:
Binding binding = fonzColumnData.Binding;
// for CSV:
string csvData = fonzColumn.CSVData;
// ...

Modifying an ObservableCollection<T> declared as a resource at runtime

I have a bunch of ObservableCollections which are populated from a database. There's agood chance that during the application lifetime these collections will grow and i need them to be updated every 30 seconds or so.
I declare the collections as resources in merged dictionaries in App.xaml. I can fetch these collections fine by using the Application.FindResource() method but any changes I make to the resulting collection are not reflected when I call FindResource again. Maybe I'm naive to think this would be the case.
Am I right or wrong?
Got it!
a resources value can be set through Application.Current.Resources[key].
So in my example, should anyone run into this problem i do something like.
MyObservableCollection coll1 = Application.FindResource("resourceName") as MyObservableCollection
foreach(Item i in coll1)
{
if(somecondition){i.someProperty == someValue;}
}
//coll2 does NOT reflect the above change!!!
MyObservableCollection coll2 = Application.FindResource("resourceName") as MyObservableCollection;
Application.Current.Resources["resourceName"] = coll1;
//coll3 DOES reflect the above change
MyObservableCollection coll3 = Application.FindResource("resourceName") as MyObservableCollection

Resources