knockout.js

Get return value of a function using notifySubscribers

自闭症网瘾萝莉.ら 提交于 2019-12-25 07:59:01
问题 I got two different view models and I need to call a function in one view model from other. To acheive this i try to use ko.subscribable() var postbox=new ko.subscribable();// global variable EmployeeViewModel postbox.subscribe(function (showAlert) { return that.ValidateEmployees(showAlert); }, that, 'ValidateEmps'); that.ValidateEmployees=function(){ //validation logic return true/false; } TaxCalculatorViewModel var isEmpValid = postbox.notifySubscribers(true, "ValidateEmps"); if (

Knockout value not being set in function

 ̄綄美尐妖づ 提交于 2019-12-25 07:55:55
问题 I am having a problem when trying to get self.material (an observable) to load a value from within a function. When trying to load the observable in the select with a value, it shows as undefined. data.materialNumber has a string value and self.materials loads correctly. Any help would be appreciated! I'll try to include only the code needed... My html: <select class="materialSelect" data-placeholder="Choose Material..." data-bind="options: materials, value: material, optionsText: function

Transitions between different knockout components

好久不见. 提交于 2019-12-25 07:53:52
问题 I'm trying to apply CSS transitions as I switch between knockout components but I'm not having much joy in achieving this. Essentially I want to have a div with a fixed width, but the internal content of which will change. As it does this I want to be able to transition the re-sizing of the element. ko.components.register("big", { viewModel: function (vm) { this.items = vm.value.items; }, template: '<div class="big box" data-bind="foreach: items"><p class="item" data-bind="text: name"></p><

Facing knockout.js binding error in chrome browser

拥有回忆 提交于 2019-12-25 07:47:45
问题 I am novice to Knockout.js. It is a new module in our project completely written using knockout.js and Template tool kit, which was developed by 3rd party team which is no more in the picture. On page load of a particular page, I am experiencing binding error in chrome where as it works perfectly fine in FF. The following is the HTML snippet which is problematic in chrome. I have copied the source from FF firebug and pasting it here. <div class="well well-xs"> <div class="field clearfix">

Getting checkbox value from json object

夙愿已清 提交于 2019-12-25 07:47:41
问题 I am currently learning and playing around with the use of the knockout js framework. I have a basic set of fields for contacts. I am able to add contacts without any problems. But I am having difficulties with setting the values for gender male and female . I have declared properly but when reading the JSON object it doesn’t display any values for gender. Why is it not showing if a contact is male or female? JSFIDDLE var initialData = [{ firstName: "Jenny", lastName: "LaRusso", phone: "(555)

Using a custom bindingHandler to update width of elements in Knockout.js

走远了吗. 提交于 2019-12-25 07:18:45
问题 I have been trying to create a menu using jQuery and Knockout and I've come up with the following here. Ideally, when the user selected a new topic I wanted to calculate the new width of all the elements and then expand the width of the newly selected topic with an animation and the previously selected elements would just change their width. The way I've managed to do it though means all the elements are updated with their width showing. Is there a nice way where I can only animate the newly

How to access outer function observable in inner function in viewmodel?

天涯浪子 提交于 2019-12-25 06:47:49
问题 I am having a main function and sub function inside that, like this: var main= function () { var self = this; self.value1 = ko.observable(""); var data = self.value1(); self.revaluate = ko.computed(function(){ data = self.self.value1(); // i am overwriting }); function inner(i1,i2) { var self= this ; self.id1=ko.observable(i1); self.id2=ko.observable(i2); self.value2 = ko.observable(""); self.visibility = ko.computed(function() { if (data == 1) {return true;} else {false;} }); } } ko

Fetching Data using .getJSON and storing using Knockout.JS

时光毁灭记忆、已成空白 提交于 2019-12-25 06:38:41
问题 My TweetModel is setup like this function TweetModel(tweet) { var self = this; this.tweet = ko.observable(tweet); } [UPDATED] Running into trouble binding the solution. For some reason, after the TweetModel object is created, it is not being pushed to self.tweets. I broke this up into steps... .getJSON(someurl, function(data){ $.each(data, function (i, val) { var tweetModel = new TweetModel(); tweetModel.tweet = data.key[0]; self.tweets.push(tweetModel); //all could be compressed into self

Drag and drop target separate from Sortable container

◇◆丶佛笑我妖孽 提交于 2019-12-25 06:38:02
问题 I'm trying to set up drag and drop cloning with Knockout and jQuery, but I can't figure this bit out. I have the knockout-sortable binding that Niemeyer wrote, but I can't find a way to hook it up how I'd like. I was hoping the connectClass would be able to "catch" drops and pass them into the child element Sortable, but apparently not. Here's a fiddle I forked from Niemeyer that shows pretty simply what I'm trying to do. http://jsfiddle.net/Kal_Torak/g74xN/3/ My Sortable bound elements aren

Knockout dirty flag event

天大地大妈咪最大 提交于 2019-12-25 06:36:27
问题 I've used the Dirty Flag Blog post here Knockmeout to implement such a flag in my model, but i can not get this to work properly. Somehow the flag is never set to true. Additionaly i want my subscribe event to be triggered every time the dirty flag is set to true. (i'll to the reset manually). Here's a fiddle that shows my issue. Can someone point me in the right direction? 回答1: A couple of small things: when you use span tags they should not be self-closing (so do <span></span> ). This was