In the following code I attempt to pass a jQuery listView selector to the function "makeObject" as a parameter. The problem I'm having is that the code doesn't recognize the .listview method of the selector in the function "createList".
I'd like a solution that does simply pass in a string and reconstruct the selector inside the called function.
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function Object() {
this.selector;
this.createList;
}
function makeObject(selector) {
var result = new Object();
result.selector = selector;
result.createList = createList;
return result;
}
function createList() {
this.selector.append("<li>list item 1</li>");
this.selector.append("<li>list item 2</li>");
this.selector.append("<li>list item 3</li>");
this.selector.listview("refresh");
}
var selectorParam = $("#testList");
var testObject = makeObject(selectorParam);
testObject.createList();
</script>
</head>
<body>
<ul id="testList" data-role="listview"></ul>
</body>
Object