gpt4 book ai didi

javascript - 用字符串数组填充 Listview

转载 作者:行者123 更新时间:2023-11-28 13:35:47 24 4
gpt4 key购买 nike

我在 http://jsbin.com/ifimadOw/11/edit 创建了一个 jsbin来说明。

我有这个 ListView 对象:

<ul id="marketplace-categories-listview" data-bind="source: results"></ul>

我有这个数据集:

dsCats = new kendo.data.DataSource({
transport: {
read: {
url: myUrl,
data: {
key: myKey
}
}
}
});

$("#marketplace-categories-listview").kendoMobileListView({
dataSource: dsCats,
template: $("#marketplace-product-template").text()
});

从 API 返回的数据如下所示:

{"count": 3, "results": ["Acupuncture Therapy","Automobiles","Lawn Care"]}

这是我的模板:

<script type="text/x-kendo-tmpl" id="marketplace-categories-template">
<li data-bind="text: this"></li>
</script>

因为我的数据没有命名元素,所以我无法在模板中使用“#:category#”之类的内容。我也尝试过数据绑定(bind)(如上所述),但到目前为止没有任何效果。当然有办法做到这一点。

最佳答案

只需在模板中使用data(这是传递给模板函数的上下文变量的名称):

  $("#category-listview").kendoMobileListView({
dataSource: dsCats,
template: "#= data #"
});

(更新JSBin)

关于javascript - 用字符串数组填充 Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21435300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com