【发布时间】:2019-06-21 15:09:44
【问题描述】:
我有几个小时的淘汰赛经验,我正在尝试修改现有的淘汰赛应用程序。它在敲除中使用模板来呈现选择列表的列表。
Tmpl 文件:
<select data-bind="options: $root.AccountIDDropList, optionsText: 'AccountID', optionsValue: 'AccountID', value: selectedAccountID.AccountID, optionsCaption:'-- Select Account --' "></select>
HTML 文件:
<div style='margin-left: 5px;' data-bind="template: { name: 'Bank', foreach: Account }"></div>
当这呈现时,我得到一个包含帐号的选择列表列表,但由于每个列表都被命名为 selectedAccountID.AccountID,当我尝试从每个列表中获取值时,我只能得到最后一个。
var AccountModel = function(data){
var self = this;
...
};
var viewModel = function(data) {
var self = this
self.selectedAccountID = ko.observable();
self.sendMe = function(){
alert(ko.toJSON({
this.selectedAccountID(),
}));
};
};
ko.applyBindings(new viewModel());
【问题讨论】:
标签: knockout.js