给定./view/listview.html,例如:
<Alloy>
<Window backgroundColor="white">
<ListView id="listView" defaultItemTemplate="template">
<Templates>
<ItemTemplate name="template" id="template">
<Label bindId="name" id="title" />
<Label bindId="position" id="subtitle" />
</ItemTemplate>
</Templates>
<ListSection id="listsection">
<ListItem template="template" class=""/>
</ListSection>
</ListView>
</Window>
</Alloy>/控制器/listview.js为:
var hrdata = [
{"n":{"text":"Adrien"},"position":{"text":"Boss"}},
{"n":{"text":"Alexandre"},"position":{"text":"Dev web"}},
{"n":{"text":"Camille"},"position":{"text":"Graphiste"}}
];
var rows = [];
for (var i=0; i < hrdata.length; i++){
var row = {
'name' : { 'text' : hrdata[i].name },
'position' : { 'text' : hrdata[i].position }
};
rows.push(row);
};
$.listsection.setItems(rows);我知道错误:
[ERROR] : The application has crashed with an uncaught exception 'NSUnknownKeyException'.
[ERROR] : Reason:
[ERROR] : [<NSConcreteValue 0x7a674520> valueForUndefinedKey:]: this class is not key value coding-compliant for the key text.
...
[ERROR] : 2015-12-16 09:13:44.686 hugoApp1[33611:1455573] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSConcreteValue 0x7a674520> valueForUndefinedKey:]: this class is not key value coding-compliant for the key text.'
...我不知道我的错误是什么。
发布于 2015-12-16 08:31:45
好的!“NSUnknownKeyException”实际上指的是我的JSON键:
var row = {
'name' : { 'text' : hrdata[i].name },
'position' : { 'text' : hrdata[i].position }
};name和/或position与以前存在的参数冲突。您通过$.listsection.setItems(rows)提供的数据不会被推入一个孤立的、空的“自定义数据”框中,而是在已经拥有一组属性的预先存在的框上。因此,您必须在和./views/listview.html中重命名您的密钥。
var row = {
'hrname' : { 'text' : hrdata[i].name },
'hrposition' : { 'text' : hrdata[i].position }
};意见(部分):
<ItemTemplate name="template" id="template">
<Label bindId="hrname" id="title" />
<Label bindId="hrposition" id="subtitle" />
</ItemTemplate>很小,不像其他一些框架,但就是它!
https://stackoverflow.com/questions/34307173
复制相似问题