简体   繁体   English

合金数据绑定找不到集合

[英]Alloy data binding can't find collection

I'm writing a simple app in which i want to try Alloy data binding, 我正在编写一个简单的应用,其中我想尝试Alloy数据绑定,

I have a model Region all set, I create a singleton by adding it in the markup 我已经设置了一个模型Region,我通过在标记中添加它来创建一个单例

<Alloy>
    <Collection id="regions" src="Region" instance="true"/>
    <Window  id="regionWin">

    <TableView id="table" dataCollection="Region">
            <TableViewRow title="{regionName}" />           
    </TableView>

    </Window>
</Alloy>

using the model in the controller just works fine 在控制器中使用模型就可以了

var c = Alloy.createCollection('Region');

var aRegion =  Alloy.createModel('Region', { '_id':'123', 'regionName':'Lazio', 'version': 43});
aRegion.save();

but in the XML nor giving the id 'regions' or the collection name 'Region' as value to the TableView attribute 'dataCollection' i got results. 但是在XML中,也没有将ID“区域”或集合名称“ Region”作为值提供给TableView属性“ dataCollection”,因此得到了结果。

the error is always 错误总是

Can't find variable: Region at RegionScreen.js (line 34) or Can't find variable: regions at RegionScreen.js (line 34) 找不到变量:RegionScreen.js的区域(第34行)或找不到变量:RegionScreen.js的区域(行34)

any suggestions? 有什么建议么?

In dataCollection you should use $.regions ($. plus the id you defined in the Collection element). dataCollection ,应使用$.regions ($。加上您在Collection元素中定义的ID)。

<Alloy>
    <Collection id="regions" src="Region" instance="true"/>
    <Window  id="regionWin">

        <TableView id="table" dataCollection="$.regions">
            <TableViewRow title="{regionName}" />           
    </TableView>

    </Window>
</Alloy>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM