我想用淘汰赛和咖啡脚本维护简单的应用程序。我想添加 Json 对象数组,例如:
[
{
Name = "",
Subscribe = "",
ScrollOfDish = [0]
},
{
Name = "",
Subscribe = "",
ScrollOfDish = [0]
}
]
这是我的代码:
class Complex
constructor: ()->
@ComplexItems = ko.observableArray()
@getAllComplex()
self = this
getAllComplex:()->
$.ajax
type: "POST"
url: "/Complex/GetAllComplex"
data: {}
dataType:"json"
contentType:"json"
success:(res)->
self.ComplexItems res // here is the problem
$(document).ready ()->
window.model = new Complex()
ko.applyBindings(model)
但是我遇到了 uncouched 类型错误 ComplexItems is not a function 的问题。当然,我尝试反向self.ComplexItems
并且model.ComplexItems
- 它不起作用 - 但我想了解为什么我的示例不起作用。