Why is optionsText in single quote? Knokcout

I am going through Knockout training.(Tutorial by John Papa).I have two questions

a)Why is shortDescription in single quotes
b)How are we able to access ‘shortDescription’ within the context of ‘lines’.shortDescription is a property in my.Product ,but then how are we able to access it directly? Shouldn’t be it like ‘my.Product.shortDescription’

my.Product=function(){      
    this.id=ko.observable();
    this.salePrice=ko.observable();
    this.photo=ko.observable();
    this.shortDescription=ko.observable();
    this.photoUrl=ko.computed(function(){
        return photoPath+this.photo;
    });
};
my.LineItem=function(){
    var self=this;
    self.product=ko.observable();
    self.quantity=ko.observable(1);
    self.extendedPrice=ko.computed(function(){
        return self.product() ? self.product().salePrice() * parseInt("0" + self.quantity(), 10) : 0;
    });
};
my.vm={
        products:ko.observableArray([]),
        lines:ko.observableArray([new my.LineItem()])
};

HTML Code

<div data-bind="foreach:lines">
<select data-bind="options:$parent.products, value:product,optionsText:'shortDescription', optionsCaption:'Select a product ...'""/>

Because it occurs in a double-quoted string. If you wanted to use double quotes, you would have to escape them:

<select data-bind="options:$parent.products, value:product,optionsText:\"shortDescription\", optionsCaption:'Select a product ...'"/>

Which looks ugly and (I think) is harder to maintain.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.