由于我是淘汰赛、网络服务和所有这些东西的新手,我正在尝试使用淘汰赛 js 和网络服务填充下拉列表。
的HTML代码是
<body>
<select data-bind="options: printers"></select>
</body>
和 javascript 块是
<script>
$(document).ready(function () {
var viewModel = {
printer: ko.observable(),
printers: ko.observableArray()
}
$.ajax({
type: "POST",
contentType: "application/json",
url: "PapersDDLs.asmx/getPrinters1",
data: "{}",
dataType: "json",
success: function (response) {
viewModel.printers(response.d);
}
});
ko.applyBindings(viewModel);
});
</script>
我调用的网络服务是
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports System.Web.Script.Serialization
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class PapersDDLs
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function getPrinters1() As String
Dim db As New DataClassesDataContext
Dim printers = From p In db.Printers Select p
Dim values As New List(Of PrinterItem)
For Each pr In printers
values.Add(New PrinterItem(pr.BrandModelName, pr.Id.ToString()))
Next
db.Dispose()
Return New JavaScriptSerializer().Serialize(values)
End Function
End Class
问题是返回的字符串是一个字符一个字符的。
任何帮助都是有价值的
谢谢!