syntax
  • knockout.js
  • hyperlink
  • 2013-08-27 51 views 0 likes 
    0

    好了,所以我能夠創建使用一個ID的鏈接:正確的語法兩個ID與Knockout.JS鏈接

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

    但是,什麼是參考兩幅ID在一個鏈接正確synatx?

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

    對不起!我對KO還很陌生。謝謝你的幫助!

    回答

    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> 
    
    相關問題