我正在使用knockoutjs
,我是新手。我想根据下拉列表选择的值更改模型数据。所以在我的 AppModel 中,我订阅了我想要更改的数组。但它不工作?这是我的代码:
var filteredStocks = [];
function viewModel(model) {
this.isGeneral = ko.observable(model.generalStockEnabled);
this.stocks = ko.observable();;
if (model.generalStockEnabled === true)
{
filteredStocks = $.grep(model.stocks, function (v) {
return v.sourceID === -1;
});
}
else
{
filteredStocks = $.grep(model.stocks, function (v) {
return v.sourceID !== -1;
});
}
// If drop downlist changed
var dropDownListSelectedValue = $('#enableGeneratInventorydl :selected').val();
this.stocks.subscribe(function () {
if (dropDownListSelectedValue === "True") {
filteredStocks = $.grep(model.stocks, function (v) {
return v.sourceID === -1;
});
this.stocks(filteredStocks)
this.isGeneral(true);
}
else
{
filteredStocks = $.grep(model.stocks, function (v) {
return v.sourceID !== -1;
});
this.stocks(filteredStocks)
this.isGeneral(false);
}
}, this);
this.stocks = ko.observableArray(filteredStocks);
当我更改下拉列表值时。股票价值保持不变?
任何帮助表示赞赏。