首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >钛合金:“NSUnknownKeyException”?

钛合金:“NSUnknownKeyException”?
EN

Stack Overflow用户
提问于 2015-12-16 08:31:45
回答 1查看 54关注 0票数 0

给定./view/listview.html,例如:

代码语言:javascript
复制
<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为:

代码语言:javascript
复制
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);

我知道错误:

代码语言:javascript
复制
[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.'
...

我不知道我的错误是什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-16 08:31:45

好的!“NSUnknownKeyException”实际上指的是我的JSON键:

代码语言:javascript
复制
    var row = {
          'name' : { 'text' : hrdata[i].name },
          'position' : { 'text' : hrdata[i].position }
    };

name和/或position与以前存在的参数冲突。您通过$.listsection.setItems(rows)提供的数据不会被推入一个孤立的、空的“自定义数据”框中,而是在已经拥有一组属性的预先存在的框上。因此,您必须在./views/listview.html中重命名您的密钥

代码语言:javascript
复制
    var row = {
          'hrname' : { 'text' : hrdata[i].name },
          'hrposition' : { 'text' : hrdata[i].position }
    };

意见(部分):

代码语言:javascript
复制
<ItemTemplate name="template" id="template">
    <Label bindId="hrname" id="title" />
    <Label bindId="hrposition" id="subtitle" />
</ItemTemplate>

很小,不像其他一些框架,但就是它!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34307173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档