Titanium Alloy ListView XML Uncaught TypeError: Object #<UI> has no method 'createTemplates'

江枫思渺然 提交于 2019-12-12 00:44:14

问题


I am new to Titanium, so excuse my lack of understanding.

Even though I am using sdk version 3.2 (have sdk-version: 3.2.0.v20130801162445 in my tiapp.xml) when I try and have a view that uses the xml above I get this error: [ERROR][V8Exception( 615)] Exception occurred at alloy/controllers/feed.js:22: Uncaught TypeError: Object # has no method 'createTemplates'

I cut down all my code so that the feed.js file is just:

function loadMoreBtnClicked(_event) {
    alert('not implemented yet');
}


function createListView(_data) {
    // this is pretty straight forward, assigning the values to the specific
    // properties in the template we defined above
    var items = [];
    for (var i in _data) {

        // add items to an array
        items.push({
            template : "template1",            // set the template
            textLabel : {
                text : _data[i].name           // assign the values from the data
            },
            pic : {
                image : _data[i].pic_square    // assign the values from the data
            }
        });
    }

    // add the array, items, to the section defined in the feed.xml file
    $.section.setItems(items);

}

alert('feed loaded');

The XML is in feed.xml and looks like this:

<Alloy>
    <Window class="container" formFactor="handheld">
        <ListView id="list" defaultItemTemplate="template1">
            <Templates>
                <ItemTemplate name="buttonItem" height="Ti.UI.SIZE">
                    <!-- will use this in the next blog post -->
                    <Button id="loadMoreBtn" onClick="loadMoreBtnClicked">Load More</Button>
                </ItemTemplate>
                <!-- main template for displaying the list items -->
                <ItemTemplate  id="template1" name="template1"  class="template1">
                    <ImageView id="pic"  bindId="pic" class="imageThumb"/>
                    <View id="textContainer">
                        <Label id="textLabel" bindId="textLabel" class="title"/>
                    </View>
                </ItemTemplate>
            </Templates>
            <!-- we only have one section and the items are contstucted using template1 -->
            <ListSection id="section" >
                <ListItem template="template1" />
            </ListSection>
        </ListView>
    </Window>
</Alloy>

I still get the error (just using the XML with no actual controller code other than the alert running). If I pull the ListView XML out of the feed.xml file the alert fires, when I put the ListView XML back in I get the Error above.

I am trying to use code from this example: https://gist.github.com/aaronksaunders/5896390 but cant really tell what I am missing?

Thanks! -James


回答1:


found out what the issue was, my problem had to do with not having the updated version of alloy that is needed to support the ListView Templates in XML. I needed to run this at the command line in Windows: "npm install -g alloy@1.2.0-alpha" (without quotes). After that I was able to use ListView templates in XML as shown above.



来源:https://stackoverflow.com/questions/18036648/titanium-alloy-listview-xml-uncaught-typeerror-object-ui-has-no-method-crea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!