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
January 16,
Try this way:
obj.defineControlProperty("dataArray", function(){return new Array(1,2,3,4,5)});
Carlos
January 16,
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)
January 16,
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
January 16,
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
January 16,
I'll give that a go, thanks.
Jim Hunter
January 17,
iObj.setControlProperty("myProperty", value)
and
iObj.getControlProperty("myProperty")
worked just fine and will do exactly what I need. Thanks again Dmitry!
Jim Hunter
January 17,