Knockout.js how to access the inner object property on data-bind

后端 未结 5 1948
春和景丽
春和景丽 2021-01-03 19:48

I\'ve a super simple knockout code below:

var data ={
    \"Id\" : 1001,
    \"SalePrice\" : 12345,
    \"ListPrice\" : 333,
    \"ShortDesc\" : \"Tayler 123         


        
5条回答
  •  耶瑟儿~
    2021-01-03 20:27

    If the page is read only, and the view model will not change, (as in my case) then you don't need the observable.

    You can also make the code sample work by doing this:

    var viewModel={
        dataTest: data
    };
    

    Then you can access your properties in the data binding with simple dot notation.

    
    

    Using a context or with binding was not desirable in my case since I would have to continually switch back and forth between 2 objects in a comparison table.

提交回复
热议问题