OPTS 내가 JSON의 목록을 렌더링하기 위해 수집 데이터 계약에 내장 중 하나를 사용하는 WCF 서비스를 정의하는 것 :
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class optionsservice
{
// Return a dynamic list of the options
[WebInvoke(UriTemplate = "/getOptions?type={type}", Method = "GET", ResponseFormat = WebMessageFormatJson)]
public SelectOptions getOptions(string filter = "")
{
SelectOptions returnOptions = new SelectOptions();
//get your datatable here.
foreach (DataRow r in tbl.Rows)
{
returnOptions.Add((string)r["id"], (string)r["value"]);
}
return returnOptions;
}
[CollectionDataContract(Name = "collection",
KeyName = "id",
ValueName = "value",
Namespace = "")]
public class SelectOptions : Dictionary<string, string> { }
}
당신은 또한 목록에 데이터 테이블을 캐스팅 수를하지만이 유일했다 어떤 데이터 형식
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8">
$(function(){
$("select#ctlSelect").change(function(){
$.getJSON("/select.php",{id: $(this).val(), ajax: 'true'}, function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].id + '">' + j[i]value + '</option>';
}
$("select#ctlSelect").html(options);
})
})
})
</script>
반환되는 : 예제 코드 나는 당신이 jQuery를에 상자를로드 할 방법은 다음과
가에 손이 있었다? xml/json? – Gthompson83
JSON 저는 믿습니다. – SidC