Reputation: 1239
I downloaded this plugin: http://code.google.com/p/jquery-autocomplete/
I write this:
$(document).ready(function () {
$('#txtStoryTags').autocomplete('@Url.Action("GetTags", "Thread")', { dataType: 'json',
parse: function (data) {
var rows = new Array();
for (var i = 0; i < data.length; i++) {
rows[i] = { data: data[i], value: data[i].Name, result: data[i].Name };
}
return rows;
},
formatItem: function (row) {
return row.Name;
},
delay: 40,
autofill: true,
selectFirst: false,
highlight: false,
multiple: true,
multipleSeparator: ";"
});
});
And the Json result is:
[{"TagID":2,"Name":"tag1","Weight":4},{"TagID":4,"Name":"tag2","Weight":1},
Until this point it's fine. But when I try to use autocomplete I get in result:
[object Object],[object Object],[object Object],[object Object],[object Object]
Well that's not expect result. The question is, what's wrong about that client script ? I'm pretty sure the problem lays here, just don't know exactly where.
Upvotes: 0
Views: 60
Reputation: 41812
I'm guessing but
formatItem: function (row) {
return row.Name;
},
...looks wrong to me. The 'rows' you provide the plugin have data
, value
and result
fields, but no Name
field.
Upvotes: 1