Im currently trying to use a jQuery plugin: jQuery Autocomplete Tokenizer Now after posting back the page, I want to re-load the values back into the textbox for whatever items had been entered.
Now the jQuery on the page is like below:
$(document).ready(function () {
$("#<%=txtPeople.ClientID %>").tokenInput("Handler.ashx", {
hintText: "Type in a name",
noResultsText: "No results",
searchingText: "Searching...",
prePopulateFromInput: true
},
prePopulate: **Here is where I want to add J开发者_JAVA技巧SON listing the items that should be populated**
});
});
If I add the JSON below within the prepopulate it loads the values the first time the form loads (And after any postbacks, so I need a way to make this a variable, that I can feed into the javascript on the page, and also have it updated by any client side changes)
[{"id":1,"name":"Ben"},{"id":2,"name":"Bernard"},{"id":3,"name":"Joe Bentley"}]
Can anyone point me in the right direction or give any references that may help? thanks
You should be able to assign the json to a variable as in..
string prepopulateValues="[{/"id/":1, /"name/":/"Ben/"}"; //etc.
then in your jquery function write out the value of the variable
prePopulate: <%= prepopulateValues%>
Or If you are using ASP.Net you can use my opensourse project ASPTokenInput which adds server side functionality to the jquery-tokeninput plugin. This will automatically take care of token persistance across postbacks.
https://github.com/harindaka/ASPTokenInput/wiki
精彩评论