var vm = {
WeatherId: ko.observable(),
WeatherConditions: [{
Id: '1',
Name: 'Sunny'
}, {
Id: '2',
Name: 'Rainy'
}, {
Id: '3',
Name: 'Cloudy'
}, {
Id: '4',
Name: 'Snowy'
}]
};
ko.applyBindings(vm);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script>
<select data-bind="options: WeatherConditions,
value: WeatherId,
optionsText:'Name',
optionsCaption: 'Select today weather'">
</select>
我有这个 KO 数据绑定(bind)片段,我想将 optionsCaption
设置为“选择今天的天气”。我无法在中间插入撇号 - 需要帮助。
最佳答案
用反斜杠转义撇号 \
optionsCaption: '选择今天的天气'">
var vm = {
WeatherId: ko.observable(),
WeatherConditions: [{
Id: '1',
Name: 'Sunny'
}, {
Id: '2',
Name: 'Rainy'
}, {
Id: '3',
Name: 'Cloudy'
}, {
Id: '4',
Name: 'Snowy'
}]
};
ko.applyBindings(vm);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js"></script>
<select data-bind="options: WeatherConditions,
value: WeatherId,
optionsText:'Name',
optionsCaption: 'Select today\'s weather'">
</select>
关于javascript - KnockoutJS 数据绑定(bind)选项Caption,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43416685/