我正在尝试实现 {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 array
Hashtag
Hashtag
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
毫无问题地访问。是什么导致了这种行为?