我不明白我在这里做错了什么!我一直收到数据错误。但我验证了JSON,它没问题......
以下是来自YUI Datatble示例的javascript(稍加修改)。
<pre class="prettyprint"><code>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
//var Ex = YAHOO.namespace('example');
var dataSource = new YAHOO.util.DataSource("jsondb/json_meta_proxy.html",{
responseType : YAHOO.util.DataSource.TYPE_JSON,
responseSchema : {
resultsList: "records",
fields: [
{key:"idprojet"},
{key:"nomprojet"}
],
metaFields: {
totalRecords: "totalRecords"
}
},
doBeforeCallback : function (req,raw,res,cb) {
// This is the filter function
var data = res.results || [],
filtered = [],
i,l;
if (req) {
req = req.toLowerCase();
for (i = 0, l = data.length; i < l; ++i) {
if (!data[i].state.toLowerCase().indexOf(req)) {
filtered.push(data[i]);
}
}
res.results = filtered;
}
return res;
}
});
var cols = [
{key:"idprojet"},
{key:"nomprojet"}
];
var paginateur = new YAHOO.widget.Paginator({
rowsPerPage : 25,
pageLinks : 10
});
var conf = {
paginator : paginateur,
sortedBy: {key:'idprojet', dir:YAHOO.widget.DataTable.CLASS_ASC}
};
var dataTable = new YAHOO.widget.DataTable('tbl',cols,dataSource,conf);
var filterTimeout = null;
var updateFilter = function () {
// Reset timeout
filterTimeout = null;
// Reset sort
var state = dataTable.getState();
state.sortedBy = {key:'idprojet', dir:YAHOO.widget.DataTable.CLASS_ASC};
// Get filtered data
dataSource.sendRequest(YAHOO.util.Dom.get('filter').value,{
success : dataTable.onDataReturnInitializeTable,
failure : dataTable.onDataReturnInitializeTable,
scope : dataTable,
argument: idprojet
});
};
YAHOO.util.Event.on('filter','keyup',function (e) {
clearTimeout(filterTimeout);
setTimeout(updateFilter,600);
});
});
</script>
以下是文件“jsondb / json_meta_proxy.html”中的JSON数据
{
"recordsReturned": 1,
"totalRecords": 1,
"startIndex": 0,
"sort": "idprojet",
"dir": "asc",
"records": [
{
"idprojet": "11256",
"nomprojet": ""
}
]
}
非常感谢你的帮助!!!
答案 0 :(得分:2)
更改为TYPE_JSARRAY解决了问题......
感谢您的评论Eric! 我去了这个论坛,它确实是数据表问题的地方。
答案 1 :(得分:0)
如果您在StackOverflow上没有得到答案,您可能想尝试将您的问题发布到YUI开发人员论坛:http://yuilibrary.com/forum。许多YUI专家,包括最有经验的DataTable开发人员,都在那里。
-Eric