我的viewModel this ..
function ViewModel() {
var self = this;
self.model = {};
self.Message = ko.observable("");
self.model.CurrentDisplayAmr = ko.observable();
self.model.SelectedAmr = ko.observable();
self.model.CurrentAmrWirings = ko.observableArray([]);
self.model.CurrentSelectedWire = ko.observable();
self.model.AmrCommands = ko.observableArray([]);
//selected Amr is update here
self.selectAmr = function (item) {
self.model.SelectedAmr(item);
self.GetAmrWirings();
};
//Amrs search is here
self.GetAmrs = function (searchTerm) {
var self = this; // Retain scope of view model
$.ajax({
url: '/AmrSearch/SearchAmrs',
cache: false,
contentType: 'application/json',
data: ko.toJSON({ AmrNo: self.SearchAmrNo }),
type: "POST",
success: function (result) {
$('#processing-modal').modal('hide');
if (result.success) {
self.model.CurrentDisplayAmr(result.data);
self.Message(result.message);
}
else
self.Message("Modem aramada sorun oluştu: " + result.message);
},
error: function (errorDetail) {
$('#processing-modal').modal('hide');
self.Message("Modem arama isteğinde hata: " + errorDetail);
}
});
}
Amr Selection html is here :
<form class="form-horizontal">
<fieldset>
<div class="col-md-4">
<div class="input-group">
<input disabled type="text" class="form-control" placeholder="0000000" data-bind="value: model.CurrentDisplayAmr.AmrRemoteId">
<span class="input-group-btn">
<button class="btn btn-default" type="button" data-bind="click: $root.selectAmr" data-toggle="modal" data-target="#processing-modal">
<span class="glyphicon glyphicon-ok"></span> Seç
</button>
</span>
</div>
</div>
</fieldset>
</form>
如果我绑定文本 self.model.SelectedAmr.AmrRemoteId 没问题。
这段代码还可以:
<span class="glyphicon glyphicon-hdd" style="font-size: 38px;"></span> <a data-bind="text:model.SelectedAmr.AmrRemoteId"></a>
结果是: 的 00000012
但如果我改变了这个:
<span class="glyphicon glyphicon-hdd" style="font-size: 38px;"></span> <a data-bind="text:'Selected Modem ' + model.SelectedAmr.AmrRemoteId"></a>
结果是
所选调制解调器未定义
为什么不能组合字符串和数值?