0

我正在尝试实现 {N} Telerik 的 UI RadListView。是他们的入门指南,我将其作为参考。

我已经设置了以下 XML 布局:

列表.xml

<StackLayout loaded="loaded" xmlns:lv="nativescript-telerik-ui/listview" xmlns="http://www.nativescript.org/tns.xsd">
    <lv:RadListView items="{{ rankingsArray }}">
        <lv:RadListView.listViewLayout>
            <lv:ListViewLinearLayout scrollDirection="vertical"/>
        </lv:RadListView.listViewLayout>
    </lv:RadListView>
    <lv:RadListView.itemTemplate>
        <StackLayout orientation="horizontal" horizontalAlignment="center" class="sl_ranking">
            <Label text="{{ name }}"></Label>
        </StackLayout>
    </lv:RadListView.itemTemplate>
</StackLayout>

基本上我将列表视图绑定到具有属性的rankingsArray包含子元素。name

实际上,这是我进行绑定的方式:

list.js var HashtagList = require("~/viewmodels/HashtagsList");

exports.loaded = function(args){
    var hashtagList = new HashtagList();
    var profile = args.object;
    profile.bindingContext = hashtagList;
}

HashtagList 是类定义为:

var Hashtag = require("~/classes/Hashtag");
var ObservableModule = require("data/observable-array");
class HashtagList{
    constructor(){
    }
    get rankingsArray(){

        if(!this._list){
            this._list = new ObservableModule.ObservableArray();
            this._list.push(new Hashtag("#pizzawithfriends"));
            this._list.push(new Hashtag("#funky"));
        }

        return this._list;
    }
}
module.exports = HashtagList;

如您所见,任何HashtagList对象都有一个返回对象的公共rankingsArray属性。这是对象的定义:observable arrayHashtagHashtag

hashtag.js

"use strict";
var Hashtag = function(name){
    var _name = name;
    //====== NAME GETTER & SETTER ======//
    Object.defineProperty(this,"name",{
        get : function(){
            return _name;
        },
        set : function(value){
            _name = value;
        }
    })
}

module.exports = Hashtag;

问题是由于某种原因我收到以下错误:

Binding: Property: 'name' is invalid or does not exist. SourceProperty: 'name'

屏幕上什么也没有出现。这很奇怪,因为如果我可以HashtagList.rankingsArray.getItem(0).name毫无问题地访问。是什么导致了这种行为?

4

1 回答 1

0

原来我label以错误的方式关闭了标签......

错误道

<lv:RadListView.itemTemplate>
        <StackLayout orientation="horizontal" horizontalAlignment="center" class="sl_ranking">
            <Label text="{{ name }}"></Label>
        </StackLayout>
    </lv:RadListView.itemTemplate>

正确的方法

 <lv:RadListView.itemTemplate>
            <StackLayout orientation="horizontal" horizontalAlignment="center" class="sl_ranking">
                **<Label text="{{ name }}" />**
            </StackLayout>
        </lv:RadListView.itemTemplate>
于 2016-06-27T13:13:03.337 回答