I decided that I needed to improve my JavaScript programming skills as well as my OO skills. I am currently reading some books, but it is sometimes difficult to get an idea of ββthis theory without first seeing practical examples. So, I have a theoretical question about "best practices" for the following scenario ...
I would like to create an OO script that displays a list of searchtag entries received from the server. I also want to be able to edit each search entry.
I am currently doing this procedurally with a little help from the jQuery library:
I am accepting a JSON encoded list of searchtag entries from the server. It looks like this:
[ { "searchTagName" : "tagOne", "searchTagID" : "1" }, { "searchTagName" : "tagTwo", "searchTagID" : "2" }, { "searchTagName" : "tagThree", "searchTagID" : "3" }, etc... ]
I remove JSON directly in jTemplates to create the corresponding html, for example:
$("#searchTagList") .setTemplateElement("template_searchTagList") .processTemplate(searchTagData);
Finally, I want to be able to change each search criteria using the in-place editing method, so I add a pre-built editing method to each html element:
$(".searchTag").editInPlace();
This works very well procedurally. And maybe the smartest thing would be to leave just one. :) But, for the sake of argument, how best to write something like that from the point of view of the OO.
Should I have one "searchTagList" object that has methods for each of the steps above?
var searchTagList = { searchTagData: JSONdata, renderList: function () { } bindEdit: function() { } }
Or is it wrong? (It seems that all I'm doing is wrapping my procedural functions in an object.) Should I somehow parse the JSON data in the instances of each search object, and then bind the individual methods to each search tag? (This seems like a lot of overhead, without benefit).
I apologize in advance if it seems to me that I am collecting hair. But I really want to get it right in my head.
Thanks,
Travis