我很努力地獲得選項綁定的選定值。敲除選項綁定獲取值
這裏是(簡化)代碼:
HTML
<div data-bind="foreach:organizations" class="accordion " id="accordionOrg">
[...]
<table>
<thead>
<tr>
<th>Billing Address</th>
[...]
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select data-bind="options: organizationAddresses, optionsText: 'address', value:'organizationAddressId'"></select>
</td>
<td>
<div data-bind="click: $root.addOrg" class="btn btn-small btn-block"></div>
</td>
</tr>
</tbody>
</table>
</div>
每個組織都有不會忽略的一個ICollection的: C#型號
public class Organization
{
public int OrganizationId { get; set; }
public string Name { get; set; }
public string SapId { get; set; }
public string UserId { get; set; }
public bool Deleted { get; set; }
public ICollection<OrganizationAddress> OrganizationAddresses { get; set; }
}
視圖模型:
var organizations = ko.observableArray();
var vm = {
organizations: organizations,
activate: activate
};
return vm;
function addOrg(organization) {
//here I need the selected value
}
一切工作我只是不知道如何獲得選定的值。 任何幫助表示讚賞!
一眼看出你可能想要爲'organizationAddressId'使用'optionsValue'綁定參數。你指的是價值和價值......你想要一個地址還是多個地址。 – Origineil
對不起,感到困惑。我想要一個地址。我提到'價值',因爲在我的應用程序中,用戶可以選擇多個地址(賬單,發貨等)。我省略了其他