I have two array of Knockout selectedSocialNetworks and List_2 all of this list can contain one social network (twitter or facebook) or both (twitter and facebook)
<script id="socNetchoiceTmpl" type="text/html">
<ul data-bind="foreach: socialNetworksList, visible: socialNetworksList().length > 0">
<li>
<input type="checkbox" data-bind="value: $data, checked:
$parent.selectedSocialNetworks" /><span data-bind="text: $data"/>
</li>
</ul>
function SocialNetChoicesViewModel() {
var self = this;
self.socialNetworksList = ko.observableArray([]);
self.selectedSocialNetworks = ko.observableArray([]);
self.List_2 = ko.observableArray([]);
self.save = function () {
if(....){
$.ajax("/Home/SocialNetworksChoice", {
data: ko.toJSON({ selectedSocialNetworks: self.selectedSocialNetworks }),
type: "post", contentType: "application/json",
success: function (result) {
if (result.Success) {
//alert(result.Message);
}
else {
alert(result.Message);
}
}
});
}
else{
$.ajax("/Home/Authentification", {
data: ko.toJSON({ socialNetworks: self.List_2 }),
type: "post", contentType: "application/json",
success: function (result) {
if (result.Success) {
//alert(result.Message);
}
else {
alert(result.Message);
}
}
});
}
};
// Load initial state from server, convert it to Task instances,
// then populate self.tasks
$.getJSON("/Home/SocialNetworksChoice", function (allData) {
var mappedItems = $.map(allData, function (item) { return item });
self.socialNetworksList(mappedItems);
});
$.getJSON("/Home/Authentification", function (allData) {
var mappedItems = $.map(allData, function (item) { return item });
self.List_2(mappedItems);
});
};
I want to detect wish social network doesn't contain in my List_2 and its in selectedSocialNetworks
I m using if than else to detect if List_2 = selectedSocialNetworks execute instruction in if ...
I'm Sorry for my bad english,
thanks,