:: Forum >> Version 2 >>
Custom Control Question
I have a control defined as follows
AW.HTML.userInfo = AW.System.Control.subclass();
AW.HTML.userInfo.create = function()
{
var obj = this.prototype;
obj.setTag("div");
obj.defineTemplate("myfield", new AW.HTML.SPAN);
with (obj.getTemplate("myfield"))
{
setClass("left-column","text");
setContent("");
}
}
Then I have made a function for that object as follows
AW.HTML.userInfo.prototype.update = function (theInfo)
{
for (var d in theInfo)
{
with(this.getTemplate(d))
{
setContent(theInfo[d]);
}
}
}
Then I pass an associative array as my parameter like this
var myUser = {'myfield':'test data'};
userInfo = new AW.HTML.userInfo;
userInfo.setId("mycontrol");
userInfo.update(myUser);
The problem revolves around this line I believe but not sure how to solve it.
Problem: ?????
with(this.getTemplate(d))
Not sure how to get the template from another defined function. Anyone?
Tony
Tuesday, January 17, 2006
Ok. Found my own answer. The code for the defined function is like
AW.HTML.userInfo.prototype.update = function (theInfo)
{
for (var d in theInfo)
{
eval('myobj = this.getTemplate("'+d+'")');
with(myobj)
{
setContent("html",theInfo[d]);
}
}
}
Tony
Tuesday, January 17, 2006
I guess you can also define it within the class itself and not externally as follows
obj.update = function (theInfo)
{
for (var d in theInfo)
{
eval('myobj = this.getTemplate("'+d+'")');
with(myobj)
{
setContent("html",theInfo[d]);
}
}
}
Tony
Tuesday, January 17, 2006
While your original function should've worked, the workaround seems to be a real kludge. Personally, I run into problems with "with()" quite often. Probably because I don't completely understand how it works. Anyway, have you tried simply:
AW.HTML.userInfo.prototype.update = function (theInfo)
{
for (var d in theInfo)
this.getTemplate(d).setContent(theInfo[d]);
}
?
Dmitry
Tuesday, January 17, 2006
Yes. That was the first thing I tried.
Tony
Tuesday, January 17, 2006
Tony, this seems to work:
AW.HTML.userInfo = AW.System.Control.subclass();
AW.HTML.userInfo.create = function()
{
var obj = this.prototype;
obj.setTag("div");
obj.defineTemplate("myfield", new AW.HTML.SPAN);
with (obj.getMyfieldTemplate())
{
setClass("left-column","text");
setContent("html", "<b>test</b>");
}
obj.setContent("html", function() {
return this.getMyfieldTemplate();
})
obj.update = function (theInfo)
{
for (var d in theInfo)
{
this.getTemplate(d).setContent("html",theInfo[d]);
}
}
}
var myUser = {'myfield':'test data'};
userInfo = new AW.HTML.userInfo;
userInfo.setId("mycontrol");
userInfo.update(myUser);
I finally got it working after chaning return this.getTemplate("myfield") to this.getMyfieldTemplate() in update(). For reasons I still don't understand, the object in 'this' didn't have a reference to 'getTemplate', but it was more then happy to provide a reference to 'getMyfieldTemplate'.
Dmitry
Tuesday, January 17, 2006
Hello,
Any one help me How to drag items inside the list box usin javascript.
Thanks a lot.
Wednesday, January 18, 2006
To the anonymous previous poster. OPEN YOUR OWN TICKET! Stop spamming all the other tickets with your questions that are unrelated you pest!
Tony
Wednesday, January 18, 2006
This topic is archived.
Back to support forum
Forum search