这个函数工作正常,但它只返回一个值。我在这里缺少什么?
这是我的代码:
<script type='text/javascript'>
$(function () {
<?php
//Get the names and id's
$get_info=mysql_query("select * from table where id = '1'");
if($get_info){
while($row_info=mysql_fetch_array($get_info))
{
$username=$row_info['name'];
$user_id=$row_info['profile_id'];
?>
onDataRequest:function (mode, query, callback) {
var data = [
{ id:<?php echo $user_id;?>, name:'<?php echo $username;?>', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' }
];
data = _.filter(data, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > -1 });
callback.call(this, data);
}
});
<?php
}}
?>
});
</script>
预期结果:
{
id: 295,
name: 'Mike',
'avatar': 'http: //cdn0.4dots.com/i/customavatars/avatar7112_1.gif',
'type': 'contact'
},
{
id: 296,
name: 'John',
'avatar': 'http: //cdn0.4dots.com/i/customavatars/avatar7112_1.gif',
'type': 'contact'
}
实际输出:
{
id: 295,
name: 'Mike',
'avatar': 'http: //cdn0.4dots.com/i/customavatars/avatar7112_1.gif',
'type': 'contact'
}
它只返回 1 个项目。