钛合金ListView XML未捕获的TypeError:对象#< UI>没有方法'createTemplates' [英] Titanium Alloy ListView XML Uncaught TypeError: Object #<UI> has no method 'createTemplates'
问题描述
我是钛合金的新手,请原谅我缺乏理解.
I am new to Titanium, so excuse my lack of understanding.
即使我尝试使用sdk 3.2版(在tiapp.xml中具有sdk版本:3.2.0.v20130801162445),当我尝试使用具有上述xml的视图时,也会出现此错误:[ERROR] [V8Exception(615)]在Alloy/controllers/feed.js处发生异常:22:未捕获的TypeError:对象#没有方法'createTemplates'
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'
我削减了所有代码,以便feed.js文件只是:
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');
XML位于feed.xml中,如下所示:
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>
我仍然收到错误消息(仅使用XML,除了运行警报外,没有任何实际的控制器代码).如果将ListView XML从feed.xml文件中拉出,则会触发警报,当我将ListView XML放回时,会出现上述错误.
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.
我正在尝试使用此示例中的代码: https://gist.github.com/aaronksaunders/5896390 但真的不能说出我在想什么吗?
I am trying to use code from this example: https://gist.github.com/aaronksaunders/5896390 but cant really tell what I am missing?
谢谢!-詹姆斯
推荐答案
发现了问题所在,我的问题与没有支持XML中的ListView模板所需的合金的更新版本有关.我需要在Windows的命令行中运行此命令:"npm install -g alloy@1.2.0-alpha"(不带引号).之后,我就能使用XML的ListView模板,如上所示.
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.
这篇关于钛合金ListView XML未捕获的TypeError:对象#< UI>没有方法'createTemplates'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!