0
我正在使用基因敲除js,ASP.Net MVC應用程序,我有一個下拉列表與一些數據綁定使用基因敲除Js。現在我想將選定的值添加到數據庫中。從下拉列表中存儲值使用敲除js
我這樣做以下方式
HTML
<select>
<!--ko foreach: products-->
<option data-bind="text: $data, value: newproductnametoadd"></option>
<!--/ko-->
</select>
<a class="btn" data-bind="click: add">Add New Entry</a>
淘汰賽JS
self.products = ko.observableArray();
self.datainput = ko.observableArray();
self.newproductnametoadd = ko.observable('Product');
self.add = function (canadiancrude) {
var payload = {
Product: self.newproductnametoadd(),
Location: "Location", Pipeline: "Pipeline"
};
$.ajax({
url: '/odata/Canadiancrudes',
type: 'POST',
// data: ko.toJSON(payload),
data: JSON.stringify(payload),
contentType: 'application/json',
dataType: 'json'
});
}
$.ajax({
dataType: "json",
url: '/odata/Canadiancrudes',
data: ko.toJSON(self.products),
async: false,
success: function (data) {
self.datainput((ko.utils.arrayMap(data.value, function (canadiancrude) {
var obsCanadianCrude = {
Id: canadiancrude.Id,
Product: canadiancrude.Product,
Location: ko.observable(canadiancrude.Location),
Pipeline: ko.observable(canadiancrude.Pipeline)
}
self.watchModel(obsCanadianCrude, self.modelChanged);
return obsCanadianCrude;
})));
}
});
self.subsetcanadiancrudes = ko.observableArray(self.datainput()).extendsdistinct('Product');
self.products = ko.computed(function() {
var products = ko.utils.arrayMap(self.subsetcanadiancrudes(), function (item) {
return item.Product;
})
return ko.utils.arrayGetDistinctValues(products).sort();
});
從數據庫成功填充數據到下拉列表,但是當我點擊添加新條目,但不會將其添加到數據庫中。