喜欢标题。我想传递几个数组作为函数参数。
var array1 = ["a", "b", "c"];
var array2 = ["d", "e"];
var array3 = ["f", "g"];
function arraysFunction(param1, param2, param3){
var a = param1;
var b = param2;
var c = param3;
}
怎么做? 提前致谢
答案 0 :(得分:0)
var array1 = ["a", "b", "c"];
var array2 = ["d", "e"];
var array3 = ["f", "g"];
function arraysFunction(any, name, youwant){
var a = any;
var b = name;
var c = youwant;
}
arraysFunction(array1,array2,array3);
答案 1 :(得分:0)
传递与任何其他变量相同的数组。
function foo( param1 ){
var a = param1;
return param1;
}
var array1 = ["a","b","c"];
console.log(foo(array1));
答案 2 :(得分:0)
好的,我会更详细地描述一下。 这是我的ajax功能
self.buyAlbum = function () {
albumViewModel.lists.removeAll();
$.ajax({
url: "api/list/",
type: "GET",
success: function (data) {
//alert(data.Converw);
albumViewModel.lists.push(new addItemForm(data.Coverw, data.PublishHousew, data.PublishYearw, data.Carrierw));
}
});
};
这是我的viewmodel
function addItemForm(c, h, y, ca) {
var self = this;
self.Coverw = x;
self.PublishHousew = ko.observableArray(h);
self.PublishYearw = ko.observableArray();
self.Carrierw = ko.observableArray();
//self.Coverw = ko.observableArray(['sth1', 'sth2']);
//self.PublishHousew = ko.observableArray(['sth3', 'sth4']);
//self.PublishYearw = ko.observableArray([1990, 1991, 1992]);
//self.Carrierw = ko.observableArray(['sth5', 'sth6']);
}
我在asp.net mvc中使用knockoutjs。
在应用程序视图中,我有四个@Html.DropDownList
元素的表单。
作为下拉列表中的选项,我想使用我的数组。当我使用它时,没关系
//self.Coverw = ko.observableArray(['sth1', 'sth2']);
//self.PublishHousew = ko.observableArray(['sth3', 'sth4']);
//self.PublishYearw = ko.observableArray([1990, 1991, 1992]);
//self.Carrierw = ko.observableArray(['sth5', 'sth6']);
但是此self.Coverw = x;
和此self.PublishHousew = ko.observableArray(h);
下拉列表为空。
我使用alert(data.Converw);
并且它的工作。