Javascript 从YUI中的数据源在网格中显示数据?
我在这个问题上附上了我的代码 我使用YUI-3以网格格式显示数据源中的数据 我无法从数据源获取数据。但数据是从URL传递的 我的网格始终显示Javascript 从YUI中的数据源在网格中显示数据?,javascript,grid,yui,yui3,Javascript,Grid,Yui,Yui3,我在这个问题上附上了我的代码 我使用YUI-3以网格格式显示数据源中的数据 我无法从数据源获取数据。但数据是从URL传递的 我的网格始终显示无数据显示 <script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script> <script> YUI().use("datatable", "datasource-get", "datasource-jsonschema", "dat
无数据显示
<script src="http://yui.yahooapis.com/3.18.1/build/yui/yui-min.js"></script>
<script>
YUI().use("datatable", "datasource-get", "datasource-jsonschema", "datatable-datasource", function (Y) {
var url = "http://domainname.com/trans/sample_json.php?format=json",
query = "&return=true",
dataSource,
table;
dataSource = new Y.DataSource.Get({ source: url });
dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: "query.results.result",
resultFields: [
"Title",
"Phone",
{
key: "Rating",
locator: "Rating.AverageRating",
parser: function (val) {
// YQL is returning "NaN" for unrated restaurants
return isNaN(val) ? -1 : +val;
}
}
]
}
});
table = new Y.DataTable({
columns: [
"Title",
"Phone",
{
key: "Rating",
formatter: function (o) {
if (o.value === -1) {
o.value = '(none)';
}
}
}
],
width:"100%",sortable: true,
summary: "Pizza places near 98089",
caption: "Table with JSON data from Datasource...."
});
table.plug(Y.Plugin.DataTableDataSource, { datasource: dataSource });
table.render("#pizza");
table.datasource.load({
callback: {
success: function (e) {
table.datasource.onDataReturnInitializeTable(e);
},
failure: function() {
Y.one('#pizza').setHTML(
'The data could not be retrieved. Please <a href="?mock=true">try this example with mocked data</a> instead.');
}
}
});
});
</script>
我找不到哪里有错误。有人能帮我吗?您的PHP看起来没有返回JSON数据。试试这个
<?php
$data = {"query": {"count": 2,"created": "2013-06-04T22:50:08Z","lang": "en-US","results": {"result":[{"Title" : "Giovannis Pizzeria","Phone" : "(408) 734-4221","Rating": {"AverageRating": "4"}},{"Title" : "Pizza","Phone" : "(800) 555-1212","Rating": {"AverageRating":"NaN"}}]}}};
header('Content-Type: application/json');
echo json_encode($data);
您的PHP看起来不像是在返回JSON数据。试试这个
<?php
$data = {"query": {"count": 2,"created": "2013-06-04T22:50:08Z","lang": "en-US","results": {"result":[{"Title" : "Giovannis Pizzeria","Phone" : "(408) 734-4221","Rating": {"AverageRating": "4"}},{"Title" : "Pizza","Phone" : "(800) 555-1212","Rating": {"AverageRating":"NaN"}}]}}};
header('Content-Type: application/json');
echo json_encode($data);
你得到的是JSON数据吗?你得到的是JSON数据吗?你得到的不是PHP数组json_encode
仅适用于PHP数组。这里没有PHP数组json_encode
仅适用于PHP数组。