0
在foreach循環內綁定相同模型的文本,但該文本不是該數組的一部分。另一個foreach循環中的數據綁定文本敲除
function SmsViewModel(data,id) {
var self = this;
// Editable data
self.Sms = ko.observableArray(JSON.parse(data));
self.Num = ko.observable('Send SMS');
self.removeNumber = function(item){
}
self.myPostProcessingLogic = function(elements) {
if ($(id).children().length === ko.toJS(self.Sms).length) {
// Only now execute handler
jq();
}
}
}
當我顯示短信的數據,它工作正常,但我不能夠在同一的foreach顯示sel.Num
<div class="modalbox_content" data-bind="foreach: {data: Sms,afterRender: myPostProcessingLogic}" id="KnockOutSmsData">
<!-- ko if: FromAddress === '+18038004697' && TypeOfMassage === 'I' -->
<div class="message_container" >
<div class="message_user_photo"><img src="images/user_pic.png" width="40" height="40"/></div>
<div class="message_cell_number"><span data-bind="text: FromAddress"></span></div>
<div class="recieved_message_container">
<div class="recieved_message_arrow"></div>
<div class="recieved_message_box">
<p><span data-bind="text: Body"></span></p>
<div class="forwd_message"><a href="#"><img src="images/frwd_msg.png"/></a></div>
<span data-bind="text: MsgDateTime"></span></div>
</div>
</div>
<!-- /ko -->
<!-- close message container -->
<!-- ko if: ToAddress === '+18038004697' && TypeOfMassage === 'S' -->
<div class="message_container" >
<div class="sent_message_user_photo"><img src="images/user_pic.png" width="40" height="40"/></div>
<div class="sent_message_cell_number"><span data-bind="text: ToAddress"></div>
<div class="sent_message_container">
<div class="sent_message_arrow"></div>
<div class="sent_message_box">
<p><span data-bind="text: Body"></span></p>
<span data-bind="text: MsgDateTime"></span></div>
</div>
</div>
<!-- /ko -->
<!-- close message container -->
</div>
我只是想比較
<!-- ko if: FromAddress === self.Num && TypeOfMassage === 'I' -->
這種自我.Num是部分
self.Num = ko.observable('Send SMS');
和FROMADDRESS是
self.Sms = ko.observableArray(JSON.parse(data));
感謝名單提前部分
dint工作的人。 – rohitarora
@rohitarora你能更具體嗎?控制檯中是否有錯誤?你確定'self.Num'包含正確的值。 Beucase在你的示例中不是一個數字,而是一個「發送SMS」文本:'self.Num = ko.observable('發送短信');'。 – nemesv
沒有實際上當點擊綁定是發生我在一個功能分配值self.Num其一個數量實際上 self.AddNum =函數(項目){ \t self.Num(item.FromAddress); \t} now self.Num is a number .. it is the value as i alert(item.FromAddress); – rohitarora