我正在通过 Knockout 将一些列表项绑定到下拉列表,但它没有绑定。我不知道我哪里错了。。
我使用了敲除映射插件,甚至尝试了一种简单的方法,但似乎没有任何效果。
我的基本结构是这样的:
BugsReport rp = new BugsReport()
{
SoftwareProductList = new List<SoftProduct>() { new SoftProduct() { ProductName = "eCommerce Website", SoftProId = 1 }, new SoftProduct() { ProductName = "Banking website", SoftProId = 2 } },
ListBugs = GetAllBugs(),
PriorityLevels = new List<Priority>() { new Priority() { PriorityId = 1, PriorityName = "P1" }, new Priority() { PriorityId = 2, PriorityName = "P2" }, new Priority() { PriorityId = 3, PriorityName = "P3" } }
};
我从控制器发送...正常的剃须刀绑定正在发生,但不是淘汰赛。
html部分
<div style="margin-top: 10px; width: 200px; float: left; font-weight: bold;">
Products
<select id="slSoftProducts" multiple="multiple" data-bind="options: $root.ProductList, value:ProductList.SoftProId, optionsText: 'ProductList.ProductName'">. </select>
</div>
<div style="margin-top: 10px; width: 200px; float: left; font-weight: bold; margin-left: 30px;">
priority Levels
<select id="slPriorityLevels" multiple="multiple" data-bind="options: $root.priorityList, value: priorityList.PriorityId, optionsText: 'priorityList.PriorityName'"></select>
</div>
和 Javascript 部分
function bugzillaviewmodel(){
var self = this;
self.ProductList = BugList.SoftwareProductList;
self.priorityList = BugList.PriorityLevels;
}
var viewModel = new bugzillaviewmodel();
// Knock Out Binding through mapping..
//var viewModel = ko.mapping.fromJS(BugList);
ko.applyBindings(viewModel);