代码之家  ›  专栏  ›  技术社区  ›  Aaron Ullal

Nativescript RadListView未绑定到源属性

  •  0
  • Aaron Ullal  · 技术社区  · 8 年前

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

    我已设置以下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 所有物

    实际上,我是这样做绑定的:

    列表.js var HashtagList=必需(“~/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 对象具有公共 等级阵列 属性返回 observable array 属于 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 没有问题。 是什么导致了这种行为?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Aaron Ullal    8 年前

    结果我关闭了 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>