Javascript 未捕获的TypeError:“optionValues”必须是{Array.| Array.
我正在尝试将select2集成到中。Backgridjs对select2提供了扩展支持,其代码如下Javascript 未捕获的TypeError:“optionValues”必须是{Array.| Array.,javascript,arrays,jquery-select2,backgrid,Javascript,Arrays,Jquery Select2,Backgrid,我正在尝试将select2集成到中。Backgridjs对select2提供了扩展支持,其代码如下 { name: "gender", cell: Backgrid.SelectCell.extend({ optionValues: [["Male", "m"], ["Female", "f"]] }), label: "Gender (SelectCell)" } 基于此,我尝试了以下方法,因为我必须从服务器加载值以选择2框 var FetchSecu
{
name: "gender",
cell: Backgrid.SelectCell.extend({
optionValues: [["Male", "m"], ["Female", "f"]]
}),
label: "Gender (SelectCell)"
}
基于此,我尝试了以下方法,因为我必须从服务器加载值以选择2框
var FetchSecurities = Backbone.Model.extend({
url : Hexgen.getContextPath("/referencedata/securities")
});
var fetchSecurities = new FetchSecurities();
{
name: "security",
label: "Security",
cell: Backgrid.Extension.Select2Cell.extend({
optionValues: fetchSecurities.fetch({
success : function() {
for(var objectPlace in fetchSecurities.attributes) {
[[fetchSecurities.attributes[objectPlace].security],[fetchSecurities.attributes[objectPlace].security]];
}
}
}),
})
}
但是我得到了这个例外,我确信我在为select2框构造值时犯了错误,但不知道如何修复它,请帮助我完成它
Uncaught TypeError: 'optionValues' must be of type {Array.<Array>|Array.<{name: string, values: Array.<Array>}>}
显然,fetchSecurities.fetch不会返回有用的结果。调查和调试!这取决于你来解决。我觉得这个问题对其他程序员来说不是很有用,应该尽快解决,但我不确定在围绕新收盘系统进行的元讨论之后,此类问题的状态如何。你的意思是说fetchSecurities.fetch必须相应地进行估值??嗯。。。您试图将某些内容传递给optionValues,这些内容必须采用特定格式,并且是fetchSecurities.fetch的结果,并且fetchSecurities.fetch返回的内容不被接受。当然,fetchSecurities.fetch不会返回兼容的对象。for循环中的语句只是创建了一个无处可去的数组,等等。也许你应该做得非常不同。感谢Jonathan,我得到了它,返回值不是预期的格式,返回值必须是“optionValues”的预期格式。我对吗??