javascript,knockout.js,viewmodel,knockout-mvcView the original page-Collection of common programming errors

UnKnown Error


  • jcolebrand
    javascript regex 2014-2-17 0:04:48
    Given this function:function doThing(values,things){var thatRegex = /^http:\/\//i; // is this created once or on every execution?if (values.match(thatRegex)) return values;return things; }How often does the JavaScript engine have to create the regex? Once per execution or once per page load/script parse?To prevent needless answers or comments, I personally favor putting the regex outside the function, not inside. The question is about the behavior of the language, because I’m not sure where to l

  • spike
    javascript browser-detection 2014-2-16 21:38:36
    Feature detection is generally preferred over browser sniffing. What should I do in a case where certain browsers “support” the features I’m using but have javascript runtimes that are too slow?I’m using the d3 library for some complicated visualizations. The visualization is very smooth in chrome / firefox, acceptable in IE9, and slow yet working in IE8. I’d like to display a banner to IE8 users telling them to upgrade and a notice banner to IE9 users that it would be faster in chrome or FF. Is

  • Robert Harvey
    javascript jquery javascript-events firefox-addon javascript-debugger 2014-2-16 20:35:16
    I’m trying to debug a webpage that makes heavy use of JavaScript events, and so I need to monitor all JavaScript events that are fired.Most of the events are bound using jQuery. Hence, it would be particularly useful if there was a way to specifically monitor only those events.

  • PrimosK
    javascript angularjs 2014-2-16 20:24:46
    Quote from one of the comments regarding ngCloak directive (AngularJS documentation):It is only really needed on your “index.html” page, because thebrowser may try to render things before Angular has had a chance toparse/compile it. At runtime, when Angular pulls in content due tong-view, ng-include, etc., it will be processed by Angular before thebrowser renders.I created a example in jsFiddle to verify this and on my surprise the expression is not evaluated before it is rendered in the browser

  • int3
    javascript google-chrome optimization compiler v8 2014-2-16 19:48:29
    I’m optimizing an sha-256 > hmac > pbkdf2 crypto algorithm in javascript for chromehttp://jsfiddle.net/dtudury/uy3hc/if I change one line (after the comment // BREADCRUMB ) ei = (di + t1) >>> 0; to ei = (di + t1); my test still passes, but the test runtime jumps from <1s to 7sI believe the >>> 0 tells chrome that it should store the value as an (actual) int… but there’s some degree of “cargo cult” to it.My question is: “is this documented anywhere?” I’d love to verify how

  • Chantz
    javascript file-upload thumbnails filepath plupload 2014-2-16 19:01:23
    I am using plupload to let users upload images. But I also want to generate thumbnails for preview before they finally decide to keep it. I understand currently “Image preview” feature is not present in plupload. So to work around this I decided to submit a new form containing just one file for each image added, & let the server process it & return a thumbnail.Now my question is how do I get the handle on the file object from the plupload so that I can create an “input” file field dynami

  • ripper234
    javascript internet-explorer internet-explorer-8 2014-2-16 18:24:22
    I’m getting ‘unspecified error’ when reading document.namespaces in IE. I can’t seem to reproduce the problem in a standalone page, my snippet is:function addNamespace(key, value) {try {$(“html”).attr(key, value);if (document.namespaces && // This throws the error!document.namespaces[key]) {document.namespaces.add(key, value);}} catch (e) {alert(“Error: ” + e);} };Never mind right now why I’m trying to add a namespace at runtime (it has to do with Facebook Like not working properly …

  • Tyler Mitchell
    javascript c#-4.0 dll dllimport winjs 2014-2-16 17:39:53
    I am new to Windows 8 app development and professional C# dev. I have run into a problem where a client wants me to interface with a printer (DYMO 450 Turbo) and the SDK only comes with a dll that has been compiled using .net 4.0 . The samples show referencing the dll from the app which I can not do because the app is written in Javascript using WinJS. The metro apps use NETCore where the dll uses NETFramework. My best solution so far is to write the code to interface with the printer as a serve

  • user502014
    javascript performance dom custom-data-attribute 2014-2-16 17:37:21
    I have a list of books and I want to store data against each book e.g. Price, Quantity, id, catergory id, size, weight etc.I was looking at storing all this in the dom by extending the li elements representing each book in the list using data- attributes. This data could then be utilised directly with javascript.However I have read that accessing data- attributes is slow in a performance sense. In addition I can have multiple instances of the same book so am a little concerened about bloat in th

  • Steven
    javascript menu unity3d subclass 2014-2-16 16:08:10
    I am trying to set up a generic class that deals with menus within Unity3D. The following code I intend to attach to an empty game objectimport System.Collections.Generic;#pragma strictpublic enum MenuType { loadSceneOnMouseDown, enableGameObject, changeValue };public class MenuClass extends System.Object{public var menuObject : GameObject;public var menuType : MenuType;}public var menuItems = List.<MenuClass>();This results in the following within the editor: I want

  • Adam Hopkinson
    asp.net knockout.js 2014-2-15 2:23:05
    Is there a way i can call JavaScript function on data-bind like this:<span id=”lblSomePropVal” data-bind=”text: MySomeFunction(SomeProperty())” ></span>What i am trying to do is call MySomeFunction with the value of SomeProperty of my viewmodel. My SomeFunction will return some text based on value passed and that will be displayed in the span lblSomePropVal.I tried it the way i have written in the example but it throws binding error.Am i missing something here or is there any other w

  • Paul Hinett
    knockout.js asp.net-web-api model-binding 2014-2-15 0:48:44
    I have a requirement for users to edit a list of quotes for a lead, the quotes can be different types such as:QuoteForProductTypeA QuoteForProductTypeBAll quote types share a common base class, such as QuoteBase.I have my quotes displaying fine on the front end, and appear to post back the correct data too.However, on the server it doesn’t obviously doesn’t know which subclass to use, so just uses the base class.I think i need some kind of custom model binder for WebApi to check for a hidden f

  • nemesv
    knockout.js 2014-2-14 0:21:18
    I am beginner in knockout, while doing samples I got error message while trying to browse my page.0x800a1391 – JavaScript runtime error: ItemToEdit is undefinedbelow is my code:$(function () {countries = [{name: France}, {name: Germany}, {name: Spain}];var viewmodel = {table: ko.observableArray(countries),ItemToEdit: function () {var editedItem = ko.dataFor(this);},};});My HTML :<a href=”#” data-bind=”click :ItemToEdit”>Edit</a>

  • Zaid Iqbal
    html pdf browser knockout.js file-download 2014-2-13 0:25:36
    I have a file in my server with file name “Acuna,_Toribio_L..pdf” but when i click on the the hyperlink it throws an runtime exception.My URL is “http://someserver.com/files/uploads/ClientApplications/Acuna,_Toribio_L..pdf”My htmml code is <ul class=”attachmentFiles” data-bind=’template: { foreach: HRBC.controllers.clientApplications.list.data }’ id=”clientApplicationsGrid”><li data-bind=”attr: { id: ‘listItem’ + Id() }”><a target=”_blank” data-bind=”attr: { href: applicationPath

  • Travis
    knockout.js typescript 2014-2-11 14:11:37
    In knockout-2.2.d.ts we have:interface KnockoutObservableAny extends KnockoutObservableBase {(): any;(value): void; }I understand that (): is used to declare a function with an empty parameter list and a return type after the colon.However I don’t understand the lack of a function identifier in front of the brackets.I would have expected something like functionName(): any; What does this “anonymous” function mean? How do I interpret this nameless function, thanks.

  • Will Gant
    javascript asp.net-mvc-4 knockout.js razor-2 2014-2-10 20:43:01
    First off, this code does work, but it gives me a low level of annoyance that I’d like to be rid of. I have a .cshtml page that is built using the razor syntax. There is a big, nasty, knockout object living behind the scenes to which many things on the page are bound. Currently, when instantiating that knockout model, I’m doing so by serializing the C# viewmodel object in question within a string literal like below.<script type=”text/javascript”>$(document).ready(function() {var data = @Ht

  • YMC
    visual-studio-2010 knockout.js 2014-2-9 7:08:18
    I like knockout.js, the only problem is Visual Studio knows nothing about this framework, so it does not prevent me from silly things like assigning some value to observable property with ‘=’ operator which makes it regular property, and it’s not easy to reveal at compile time and often at runtime even. I wonder is there any syntax checker/highlighter for Visual Studio 2010 that helps me prevent faults like this? What about VS 2011? It might be a great help for developers who are new to knockou

  • Charlie
    ajax html5 knockout.js 2014-2-8 23:44:17
    I’m using Knockout JS and have a main view and view model. I want a dialog (the jquery UI one) to popup with another view which a separate child view model to be bound to. The HTML for the dialog content is retreived using AJAX so I want to be able to call ko.applyBindings once the request has completed, and I want to bind the child view model to just the portion of the HTML loaded via ajax inside the dialog div.Is this actually possible or do I need to load ALL my views and view models when the

  • woggles
    knockout.js 2014-2-6 13:07:38
    Is this a knockout bug?<h2>Debugging Variables</h2> <div data-bind=”text: ko.toJSON($root, null, 2)”> </div>I get the following error when viewing my page in compatability mode: Microsoft JScript runtime error: Unable to parse bindings. Message:[object Error]; Bindings value: text: ko.toJSON($root, null, 2)Works fine when compatability mode is off.

  • Tomalak
    dependencies knockout.js 2014-2-2 13:59:45
    Is there a way in knockout.js to determinewhich values (ko.observable or ko.computed) depend on each other in what way (precedents/dependents) and which HTML nodes (text binding, for starters) depend on the current value1, so I can highlight them on screen.?1 This implies that I need a way to go from an HTML node to the connected ko.subscribable, not just to the view model, like ko.dataFor() does. This seems to be impossible as well.I’ve built a web application that works like a spreadsheet – m

  • marcind
    asp.net-mvc viewmodel viewdata asp.net-mvc-3 2014-2-8 15:52:09
    In my understanding, the ViewModel pattern was designed to pass all the relevant data to View because 1) the view shouldn’t perform any data retrieval or application logic and 2) it enables type-safety, compile-time checking, and editor intellisense within view templates.Since dynamic expressions are defined at runtime, does this mean we don’t get any of the 2)’s goodies?

  • Boas Enkler
    viewmodel mvvm-light 2014-2-5 20:37:05
    In our application customers can design their ui on their on. For this we load the generated XAML at runtime.We use MvvmLight as Mvvm Framework.But I’m not sure what the best way is to get some kind of a dynamic view model.So if the customer wants a new Datafield it should be aviable in the model.My idea is to dynamically generated and compile a model assembly or to have converters which get their data from a Dictionary which is placed on the viewmodel.Are there any better ideas, or some experie

  • gabe
    asp.net-mvc asp.net-mvc-3 viewmodel access-modifiers strongly-typed-view 2014-2-4 3:24:01
    I have some internal automatic properties in my view model but my strongly-typed view doesn’t see them. Everything is in the same assembly, so why is this happening?public class MyViewModel {public int PublicProperty { get; set; }internal int InternalProperty { get; set; } }.@*My view*@ @model [email protected]@Model.InternalProperty @*Causes compilation error*@

  • Mike Kantor
    asp.net-mvc razor viewmodel 2014-1-19 19:50:53
    depending on configuration at each site, some fields on a form may or may not be required. Can I apply the [Required] attribute to fields of my ViewModel in code? I’d like to take advantage of all the conveniences of form validation, but I can’t hard-code the [Required] attribute.

  • Matt Mangold
    asp.net-mvc asp.net-mvc-3 dynamic views viewmodel 2014-1-19 18:39:22
    Traditionally, I have built MVC applications using view models with Data Annotations attributes, and I dynamically render the views using editor templates. Everything works great, and it really cuts down on the time it takes me to build new views. My requirements have recently changed. Now, I can’t define the view model at design time. The properties that will be rendered on the view are decided at run time based on business rules. Also, the validation rules for those properties may be deci

  • Jackson Dean Goodwin
    wpf binding user-controls window viewmodel 2014-1-18 17:20:12
    I have a portion of a Window that should display one of several UserControls. Each UserControl presents the same data, only in a different format, arrangement, and style. The particular UserControl that will be presented in this section of the Window should be determined by a single setting that is stored in the ViewModel of the Window.How can I make it so that the program end user can change the UserControl that is displayed in the Window at run-time?

  • Brendan Hill
    c# mvc viewmodel strong-typing 2014-1-7 3:41:48
    I see a lot of posts about strongly typing the View’s model data.I am interested in somehow strongly typing the View itself.It concerns me that a controller action returning View(xyz) could crash at run-time, if the view’s model type changes, or the name / location of the view itself changes. In my opinion, the loose coupling of the MVC framework goes too far in this specific area, becoming counterproductive in a RAD environment. (not getting immediately notification of breaking changes)Is there

  • FrankCap
    c# windows-phone-7 viewmodel webclient 2014-1-2 15:28:17
    I have a refresh button to update news in my WP7 application. When I double or triple click on the refresh button I am getting an error”WebClient does not support concurrent I/O operations” .I think thats because It is sending the request triple times and making it crash. Here is my Click code.private void NewsRefresh_Click(object sender, RoutedEventArgs e){var vm = this.DataContext as MainPageViewModel;if (vm != null){vm.UpdateNews();}}How can I turn it as “if It is busy cancel the process”.

  • Naser Asadi
    wpf constructor viewmodel 2013-12-30 20:28:41
    how can I datatemplate a UserControl with a ViewModel with a NON-Empty constructor ?public PersonViewModel(Person person) {_person= person;// do some stuff }Binding this in Xaml will crash as the Ctor is not empty. But as I use parent/child relations with the ViewModels I have to pass the person object to the constructor of the ViewModel…How do you cope with that situation?

  • teresko
    asp.net-mvc razor dictionary checkbox viewmodel 2013-12-4 23:01:06
    I’m using MVC 4, .Net 4, and Visual Studio 2012.I’m trying to use a fairly complex model with one of my views, and I’m having serious trouble getting it to bind properly.The model wraps a Dictionary with integer Keys, and Values that are Lists of Lists of bools.Basically, a search was done on items indicated by the integer, each item had several search terms, and for each of those terms we have a list of results. I display the results on a page, and have a checkbox next to each result. For each

  • Shelby115
    razor knockout-mvc 2013-11-25 7:43:07
    I’m learning KnockOut-MVC and I’m getting an error when my page reaches the @ko.Apply(Model) line.@using PerpetuumSoft.Knockout @model NMBS.EstimateTools.Models.ViewEntity @{var ko = Html.CreateKnockoutContext(); } <table id=”table-entities”><thead><tr>@foreach (String Name in this.ViewData.Model.PropertyNames){<td>@Name</td>}</tr></thead><tbody>@using(var Entities = ko.Foreach(e => e.Entities)) // Entities -> List<Entity>){<tr>@u

  • Zane
    c# asp.net-mvc-3 knockout.js knockout-mvc 2013-11-12 3:41:40
    Model:public class DishesModel {public Dish DishToAdd{get; set;}public List<Dish> AllDishes{get; set;}public List<Category> AllCategories{get; set;}public List<Dish> SelectedDishes{get; set;}public DishesModel(){DishToAdd = new Dish();}public void AddDish(){if(DishToAdd!=null && !AllDishes.Contains(DishToAdd)){AllDishes.Add(DishToAdd);DishToAdd = null;}}public void RemoveSelected(){AllDishes.RemoveAll(d=>SelectedDishes.Any(m=>m.Name==d.Name));SelectedDishes.Clear(

  • BillPull
    javascript knockout.js viewmodel knockout-mvc 2013-9-19 0:29:58
    I am trying to create and initialize some sort of master view model that contains common view models that might be run on every page and page specific models that are appended on page load.var MasterViewModel = {commonViewModel1 : CommonViewModel1(),commonViewModel2 : CommonViewModel1() };var commonInit = function() {// Populate View Model DataMasterViewModel.commonViewModel1 = initCommonViewModel1();MasterViewModel.commonViewModel2 = initCommonViewModel2();// Apply common view model bindingsko.

  • user1813251
    knockout.js knockout-2.0 knockout-mvc 2013-9-16 4:46:51
    I want to send the viewmodel to my controller in mvc4. Everything I have tried comes back as the viewmodel is undefined. Everything else works fine. The page generates and shows all the values it should, but I can’t seem to change the vm to json and send via postview modelvar guideviewmodel = function () { var self = this; self.scencustlist = ko.observableArray([]); …}ko.applyBindings(new guideviewmodel);I have tried it both in the viewmodel and outside.$(“#export”).on(“click”, function (model

  • acchu1986
    javascript knockout.js knockout-mvc 2013-8-29 13:24:23
    I am displaying a list of items and if the items are not available I have to display a default message. Now, I have to check whether the object has been created and then check the object has the list in it. So now, I am doing the below and it works it creates unnecessary dom elements. But, when I do the same with the containerless binding it doesn’t seem to work and also is there an && syntax for if in KO <span data-bind=”if: object”> <span data-bind=”if: !object().property”>

  • Rohan Büchner
    javascript knockout.js asp.net-web-api durandal knockout-mvc 2013-8-21 13:03:08
    I’ve got a single screen with multiple dropdowns. Each get populated via a web api call. I’m in an active directory environment. I’m using the Durandal SPA framework.At the moment I do the loading of my dropdowns on the activate of my view. EG.activate: function (data) {var id = data.id || undefined;userRole(data.mode || ‘usr’);// i added this as i was thinking i dont need to initialize the “static” dropdowns every time// I’m testing my code without this as we speak.if (!hasBeenInit) {lookupInit

  • Display Name
    asp.net-mvc internet-explorer knockout.js knockout-validation knockout-mvc 2013-8-16 6:26:13
    In my razor view that using knockout and supposedly knockout validation I add the following line (to actually start using ko validation):<script src=”@Url.Content(“~/Scripts/knockout.validation.debug.js”)” type=”text/javascript”></script>When I run this view in Chrome validation is working perfectly. When I run this view in IE (9.0), I get pretty ugly message saying the following:0x800a138f – Microsoft JScript runtime error: Unable to get value of the property ‘rules’: object is null

  • j0k
    javascript knockout.js asp.net-web-api knockout-mvc 2013-6-27 21:35:33
    I’m facing problems while sending AJAX call from one of my Knockout.js model function.This seems very weird to me. My Knockout Script looks like <script type=”text/javascript”>var userinfoViewModel = function () {var self = this;self.ID = ko.observable(“0”);self.First_Name = ko.observable(“”);self.Last_Name = ko.observable(“”);self.Login_Id = Ko.observable(“”);self.Password = ko.observable(“”);self.Role = ko.observable(“”);var user = {ID: self.ID,First_Name: self.First_Name,Last_Name: sel