-1

I am trying to add a row to the table. The table is created in alloy and I am trying to append the rows from the js.

Here is the xml

<Alloy>
<Window id='index' class="container">
    <TableView  id="MainThings">
        <TableViewSection id='MainThingsSection'>

            </TableViewSection>
    </TableView>
    <Label id="AddCounter" onClick="doClick">+</Label>
    <Label id="clear" onClick="clear">-</Label>
</Window>

Here is the .js

function Loader(){
var row= Titanium.UI.createTableViewRow({
    title:'Title'
});
$.MainThingsSection.append(row);
}$.MainThings.addEventListener('open',Loader());
$.index.open();

Here is the error

[ERROR] :  Script Error {
[ERROR] :      backtrace = "#0 () at file:///Users/stephenhanrahan/Library/Developer/CoreSimulator/Devices/C088B99B-2086-4FA3-AABD-85E2B4BE3944/data/Containers/Bundle/Application/A8E9395F-44CF-4699-92EC-9638E2473142/I%20Have%20This%20Many.app/alloy.js:265";
[ERROR] :      line = 93;
[ERROR] :      message = "Invalid type passed to function";
[ERROR] :      nativeLocation = "-[TiProxy addEventListener:] (TiProxy.m:824)";
[ERROR] :      nativeReason = "expected: Function, was: NSNull";
[ERROR] :      sourceId = 286306016;
[ERROR] :      sourceURL = "file:///Users/stephenhanrahan/Library/Developer/CoreSimulator/Devices/C088B99B-2086-4FA3-AABD-85E2B4BE3944/data/Containers/Bundle/Application/A8E9395F-44CF-4699-92EC-9638E2473142/I%20Have%20This%20Many.app/alloy/controllers/index.js";
[ERROR] :  }
Searock
  • 6,278
  • 11
  • 62
  • 98

2 Answers2

0

The error in this code is that it doesn't like the line.:

$.MainThings.addEventListener('open',Loader()); 
Should Be
$.MainThings.addEventListener('open',Loader); 

This is aside from the TableView not having an 'open' event, so this code won't link the event the way you are trying.

index.xml

<Alloy>
    <Window id='index' class="container">
        <TableView  id="MainThings">
            <TableViewSection id='MainThingsSection'>

            </TableViewSection>
        </TableView>
        <!-- <Label id="AddCounter" onClick="doClick">+</Label> -->
        <!-- <Label id="clear" onClick="clear">-</Label> -->
    </Window>
</Alloy>

index.js

function Loader(){
    console.log("This code doesn't run."); // <====== This doesn't run.
    var row = Ti.UI.createTableViewRow({
        title:'Title'
    });
    $.MainThingsSection.add(row);
}

$.MainThings.addEventListener('open', Loader); // <===== This is nothing.
$.index.open();
Martin
  • 1,914
  • 1
  • 12
  • 14
0

there is no need to use $.MainThings.addEventListener('open',Loader()); code. instead that you can directly call Loader() function before $.index.open().

and instead of using append method use appendRow method

$.MainThingsSection.appendRow(row);

Note: Before the table is rendered, the TableViewSection add method may be used to add TableViewRow objects to a section. After it is rendered, one of the TableView insertRowBefore, insertRowAfter, or appendRow methods must be used instead.