2013-08-03 32 views
0

我是鈦新來的,所以請原諒我缺乏理解。鈦合金ListView XML未捕獲TypeError:對象#<UI>沒有方法'createTemplates'

即使我使用sdk 3.2版(在我的tiapp.xml中有sdk-version:3.2.0.v20130801162445),當我嘗試使用上述xml的視圖時,出現此錯誤: [ERROR] [V8Exception(615)]在合金/ controllers/feed.js發生異常:22:Uncaught TypeError:Object#沒有方法'createTemplates'

我減少了所有的代碼,以便feed.js文件只是:

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,看起來像這樣:

<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放回時,會觸發警報,我會在上面看到Error。

我想使用這個例子中的代碼: https://gist.github.com/aaronksaunders/5896390 但我真的不知道我錯過了什麼?

謝謝! -James

+0

找出問題所在,我的問題與沒有支持XML中ListView模板所需的更新版合金有關。我需要在Windows的命令行中運行它:「npm install -g [email protected]」(不含引號)。之後,我可以像上面那樣使用XML中的ListView模板。 – contractorwolf

+0

在這裏看看更多關於更新(和還原)你的合金版本:http://docs.appcelerator.com/titanium/3.0/#!/guide/Alloy_Quick_Start – contractorwolf

+0

我的不好,我會添加一個評論給它的要點要求合金1.2工作 –

回答

0

找出問題所在,我的問題與沒有支持ListView模板所需的合金更新版本有關。我需要在Windows的命令行中運行它:「npm install -g [email protected]」(不含引號)。之後,我可以像上面那樣使用XML中的ListView模板。

相關問題