$(document).ready(function () { //debugger; $("#txtValue").autocomplete({ source: '@Url.Action("Getbusiness")', minLength: 2, maxResults: 5 });
我从数据库表中获取所有数据..我只需要显示自动完成列表中的5个项目..怎么做?请帮我解决这个问题
Am getting all data from database table.. i need to display only 5 items in auto-complete list.. how to do that ?? kindly help me to solve this
推荐答案(document).ready(function(){ // 调试器; (document).ready(function () { //debugger;
( #txtValue)。autocomplete({ so urce:' @ Url.Action(Getbusiness)', minLength: 2 , maxResults: 5 }); ("#txtValue").autocomplete({ source: '@Url.Action("Getbusiness")', minLength: 2, maxResults: 5 });
b $ b 我从数据库表中获取所有数据..我只需要在auto中显示5项完整清单..怎么做?请帮助我解决这个问题
Am getting all data from database table.. i need to display only 5 items in auto-complete list.. how to do that ?? kindly help me to solve this
这在jQuery中不起作用,因为实际中的jQuery不是从数据库服务器中提取数据而是它是你的服务器端语言记录,然后传递给自动完成。而不是寻找jQuery解决方案,在服务器端进行更改,更改您的SQL查询 That won't work in jQuery because jQuery in real isn't pulling the data from your database server instead it is your server-side language which is pulling the records and then passing to that autocomplete as a result. Rather than looking for jQuery solution, make changes on your server side, change your SQL query from SELECT * FROM...
to
to
SELECT TOP 5 * FROM...这样可以确定从您的数据库中只选择了前5条记录。 jQuery与这个逻辑无关。 jQuery只会发送异步请求并提取响应。而已。实际的逻辑将在那里实现。 个人提示是将变量发送到服务器以提取数据。例如,尝试将查询字符串附加为 getbusiness?records = 5 。使用记录值并获取记录数。 永远不要对源代码进行硬编码,以后很难对其进行升级,而是根据您最近和将来的需要制作一些可以轻松编辑的案例。
This would make sure that only top 5 records are selected from your database. jQuery has nothing to do with this logic. jQuery would just send an asynchronous request and pull the response. That's it. The actual logic would be implemented there. A personal tip would be to send a variable to server to pull data. For example, try appending a query string as, getbusiness?records=5. Use the value for records and get the number of records. Never hard-code your source code, it would make it hard to upgrade it later instead make a few cases which can be easily edited as per your recent and future needs.
更多推荐
如何在ajax mvc中显示限制结果
发布评论