0

好的,所以我可以使用一个 id 创建一个链接:

<td><a data-bind="text: productTypeId, attr: {href: '/*******WebAdmin2/ProductManager/ProductTypeDescriptionEditor.aspx?ProductTypeID=' + productTypeId}" target="_new"></a></td>

但是在链接中引用两个 id 的正确语法是什么?

<td><a data-bind="text: wsNotes, attr: {href: '/****webadmin2/Common/PopupWindows/ManufacturerBlurbEditor.aspx?manufacturerid= + manufacturerBlurbID, &stylecode=styleCodeId'}" target="_new">Edit Blurb</a></td> 

对不起!我对 KO 还是很陌生。谢谢你的帮助!

4

1 回答 1

2

你可以这样做:

<td><a data-bind="text: wsNotes, attr: { href: '/****webadmin2/Common/PopupWindows/ManufacturerBlurbEditor.aspx?manufacturerid=' + manufacturerBlurbID + '&stylecode=' + styleCodeId }" target="_new">Edit Blurb</a></td> 

更好的方法是将 url 创建逻辑从视图移动到您的视图模型,例如:

var MyViewModel = function (data) {
    this.styleCodeId = ko.observable(data.styleCodeId);
    this.manufacturerBlurbID = ko.observable(data.manufacturerBlurbID);

    this.manufacturerUrl = ko.computed(function () {
        return '/****webadmin2/Common/PopupWindows/ManufacturerBlurbEditor.aspx?manufacturerid=' + this.manufacturerBlurbID() + '&stylecode=' + this.styleCodeId();
    }, this);
};

在您看来,您像这样引用它:

<td><a data-bind="text: wsNotes, attr: { href: manufacturerUrl }" target="_new">Edit Blurb</a></td>
于 2013-08-27T18:46:39.650 回答