:: Forum >> Version 2 >>

storing arrays in data models?

Hi,

I thought it was possible to store arrays and objects in data models. If true, what's wrong with this approach?

AW.UI.Test AW.UI.Input.subclass();
AW.UI.Test.create = function()
{

   var 
obj this.prototype;

   
obj.defineControlProperty("dataArray", new Array(1,2,3,4,5));
   
obj.setEvent("onkeypress", function() {alert(this.getControlDataArray())});
   
}
 
when alert box is displayed, it shows "undefined" but if I change "new Array) to a non-object value, it shows the correct value.


Dmitry
Dmitry
Monday, January 16, 2006
Try this way:
obj.defineControlProperty("dataArray", function(){return new Array(1,2,3,4,5)}); 
Carlos
Monday, January 16, 2006
Dmitry,

if you want an array or object be interpereted as single value - you have to call defineXXXProperty(name, value, isArray) method with a third optional argument set to true -

obj.defineControlProperty("dataArray", new Array(1,2,3,4,5), true); 
 
Alex (ActiveWidgets)
Monday, January 16, 2006
thanks, Alex!

FYI, this third parameter does seem to be documented: http://activewidgets.com/active.system.model/defineproperty.html. Unless I wasn't looking in the right place.
Dmitry
Monday, January 16, 2006
Alex, I see a defineProperty in AW.System.Model but I don't see any reference to defineControlProperty. I was trying to simply add a string property to my control and I am not having much luck. I don't get an error when I do the define but when I try to set a value it doesn't go so well. I tried:

iObj.setControlProperty("myProperty", "new Value")
and
iObj.setMyProperty("new value")

and they both failed. What is the correct method of creating and setting a string property?
Jim Hunter
Monday, January 16, 2006
Jim,

You have to define the property first:

iObj.defineControlProperty("myProperty", initialValue);

after this you can use

iObj.setControlMyProperty(value) or iObj.setControlProperty("myProperty", value)
and
iObj.getControlMyProperty(); or iObj.getControlProperty("myProperty")

generally, a call to obj.defineModel("modelName")

will create a new set of methods:

obj.get<ModelName>Model
obj.set<ModelName>Model
obj.define<ModelName>Property

a call to obj.define<ModelName>Property("propertyName")

will add a new set of methods:

obj.get<ModelName><PropertyName>
obj.set<ModelName><PropertyName>
Dmitry
Monday, January 16, 2006
I'll give that a go, thanks.
Jim Hunter
Tuesday, January 17, 2006
iObj.setControlProperty("myProperty", value)
and
iObj.getControlProperty("myProperty")

worked just fine and will do exactly what I need. Thanks again Dmitry!
Jim Hunter
Tuesday, January 17, 2006



This topic is archived.

Back to support forum

Forum search