【发布时间】:2012-12-03 15:07:59
【问题描述】:
我是剑道新手,遇到了一个问题。我正在尝试在我的剑道应用程序中添加一些远程 json,然后将其添加到模板/列表视图中。我可以在 chrome 开发工具网络选项卡和 console.log(this.view()); 中看到响应在我的数据源更改方法中,我在控制台中获得了某种剑道代码,其中包含我的结果
但我似乎无法将结果添加到我的模板中?这是我的代码,希望你能指出我正确的方向,因为我喜欢剑道,但需要解决这个问题才能继续前进……或者回到 jquery mobile。提前致谢。
<body onload="onBodyLoad()">
<!-- Home page -->
<div data-role="view" data-layout="default" id="home">
<p>Home</p>
</div>
<div data-role="view" data-layout="default" id="search">
<div class="form">
<button id="getProperties" name="getProperties" value="Get Properties" data-role="button">Get Properies</button>
</div>
<ul id="resultListView"/>
</div>
<!-- Settings -->
<div data-role="view" data-layout="default" id="settings">
<p>Some settings</p>
</div>
<!-- Layout -->
<section data-role="layout" data-id="default">
<header data-role="header">
<div data-role="navbar">My app</div>
</header>
<!--View content will render here-->
<footer data-role="footer">
<div data-role="tabstrip">
<a data-icon="home" href="#home">Home</a>
<a data-icon="search" href="#search">Search</a>
<a data-icon="organize" href="#calculator">Calculator</a>
<a data-icon="settings" href="#settings">Settings</a>
</div>
</footer>
</section>
<script src="js/jquery.min.js"></script>
<script src="js/kendo.all.min.js"></script>
<!-- Template for Property results, need to change below fields -->
<script type="text/x-kendo-template" id="propertiesListViewTemplate">
<h4>${property_type}</h4>
<p>${street_name}</p>
</script>
<script>
var app = new kendo.mobile.Application(document.body,
{
transition:'slide'
});
function onBodyLoad() {
getProperties(onResult);
}
function getProperties(callback) {
var template = kendo.template($("#propertiesListViewTemplate").html());
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: 'http://www.someurl.me/getproperties.php?postcode=hx59ay',
dataType: "jsonp"
}
},
schema: {
data: "listing"
},
error: function(e) {
console.log("Error " + e);
},
change: function() {
$("#propertyResultListView").html(kendo.render(template, this.view()));
console.log(this.view());
}
});
dataSource.read();
$("#propertyResultListView").kendoMobileListView({dataSource:dataSource,template: $("#propertiesListViewTemplate").html()});
}
function onResult(resultData) {
console.log("Results " + listing); // This isnt getting logged in console...
$("#propertyResultListView").kendoMobileListView({dataSource: kendo.data.DataSource.create({data:resultData}),
template: $("#propertiesListViewTemplate").html()});
}
</script>
【问题讨论】:
-
您介意展示检索到的 JSON 的样子吗?据我所见,它应该是一个 JSON 对象,其中包含一个名为列表的元素。那是对的吗?列表是什么样的?
标签: kendo-ui