Search Results

Search found 13794 results on 552 pages for 'variable scope'.

Page 11/552 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • ngModel and component with isolated scope

    - by Artem Andreev
    I am creating simple ui-datetime directive. It splits javascript Date object into _date, _hours and _minutes parts. _date uses jquery ui datepicker, _hours and _minutes - number inputs. See example: http://jsfiddle.net/andreev_artem/nWsZp/3/ On github: https://github.com/andreev-artem/angular_experiments/tree/master/ui-datetime As far as I understand - best practice when you create a new component is to use isolated scope. When I tried to use isolated scope - nothing works. ngModel.$viewValue === undefined. When I tried to use new scope (my example, not so good variant imho) - ngModel uses value on newly created scope. Of course I can create directive with isolated scope and work with ngModel value through "=expression" (example). But I think that working with ngModelController is a better practice. My questions: Can I use ngModelController with isolated scope? If it is not possible which solution is better for creating such component?

    Read the article

  • Java-script object - get variable name

    - by Mikk
    Hi, To begin with, I'm not even sure, if it is the right way to do it. Let's say, i have script (jquery included) like this: foo = function() { this.bar = function() { alert('I\'m bar'); } this.test = function() { $('body').append('<a onclick="my_var.bar();">Click me</a>'); } this.test(); } var my_var = new foo(); Is there any way, i could make variable "my_var" dynamic inside function "foo". So I could do something like $('body').append('<a onclick="'+the_variable_which_im_assigned_to+'.bar();">Click me</a>'); Thank you

    Read the article

  • Using the value of a variable as another variables name in Ruby

    - by hrickards
    Hi, I'm just starting out in learning Ruby and I've written a program that generates some numbers and assigns them to variables @one, @two, @three etc. The user can then specify a variable to change by inputting it's name (e.g one). I then need to do something like '@[valueofinout] = asd'. How would I do this, and is there a better way as the way I'm thinking of seems to be discouraged? I've found x = "myvar" myvar = "hi" eval(x) -> "hi" but I don't completely understand why the second line is needed. In my case would I use something like @one = "21" input = "one" input = "@" + input changeto = "22" eval(input) -> changeto Thanks

    Read the article

  • JQuery selector in variable

    - by nagut
    I wanted to ask about using selector from a variable first I have: function check() { $('.info input, .info select').each(function(n, element){ if ($(element).val()=='') alert('empty'); }); } and called it in $('input')change(check); and they worked fine. But now I want to pass some value to the function to make it dynamic, like $('input')change(check('.info')); and changed the function to function check(sel) { $(sel +' input, '+ sel + ' select').each(function(n, element){ if ($(element).val()=='') alert('empty'); }); } but it doesn't work. Any help please.. Thanks, nagut

    Read the article

  • Global javascript variable not accessible in jquery change event

    - by Dan
    I have to be missing something simple, but I'm really not sure what. I'm not a JS veteran, so this may be an easy answer - sure hope so :). I have a button that, when clicked, gets JSON data. When a drop-down is changed, I check to see if there is data, if there is, I want to clear it out as the drop-down indicates what data to retrieve when the button is clicked The Code: var selected, $locDialog; var locations = []; $(function() { // Save the selected Name selected = $("#selected option:selected").val(); // Setup Dialog for Locations $locDialog = $('#location-dialog').dialog({ autoOpen: false }); // If user changes the selected // 1. Prompt for confirmation // 2. If users confirms, clear data $('#selected').change(function() { if (locations) { var confirmed = confirm("Oh Rly?"); if (confirmed) { // Clear data var locations; } } }); // When user clicks "Location" Button.. $('.loc-select button').click(function() { if (!locations) { $.getJSON("/Controller/JSONAction", { selectedId: selected, pageNum: 1, pageSize: 100 }, function(data) { locations = data; $.each(locations, function(index, loc) { var $tr = $('<tr/>') .append($('<td/>') .append('<input type="checkbox" name="TEST-'+index+'" value="'+loc.Id+'"/>')) .append('<td>' + loc.Name + '</td>'); $("#location-dialog table tbody").append($tr); }); }); } $locDialog.dialog('open'); return false; }); }); Here's the thing, Inside the .click(...) callback, I can see locations is []. Now, when I am in the .change(...) callback, I see locations is undefined. Any help/insight, as always, is appreciated!

    Read the article

  • Problem with variable inside gsp

    - by xain
    Hi, I have a loop inside a gsp page, and I want to do a calculation on the fly, so I set a variable: <g:set var="total" value="0" /> And in the loop: <g:each in="${mob}" var="m"> ... <g:set var="total" value="${total+(m.q*m.sts.uf)}"/> ... </g:each> The "total" value does not correspond to the expected calculation. m.q is an integer, and m.sts.uf is a float. Any hints ? Thanks.

    Read the article

  • PHP Global variable in class is reset

    - by Robert
    I have a web form that manipulates records in a MySQL database. I have a method for displaying an edit interface for both creating new records and editing them if ($_POST['new_page']) { print "<h2>Create new page</h2>\n"; $isNew=1; $this->EditForm(); } else if($_POST['edit']){ print "<h2>Edit page</h2>\n"; $isNew=0; $this->EditForm(); } I am trying to use the global variable $isNew to determine where a record is to be added or updated. However, whenever my SaveChanges() function is run, $isNew is always 0. $isNew is declared immediately after the class declaration, outside all of the functions. class Editor{ public $isNew;

    Read the article

  • Pass variable name to a function in r

    - by Misha
    Is it possible to pass just a variable name in a function call and have it utilised as such within the function?? pseudocode: q<-function(A){ b<-(w%in%A.2|w%in%A.7) factor(b,levels=c(F,T),labels=c("non-"A,A))} w<-c(0:10) e.2<-c(1,2) e.7<-c(6,7) what I´d like to do is q(e) and have returned non-e,e,e,non-e,non-e,e,e,non-e,non-e //M q<-function(A) { a2<-get(paste(a,".2",sep="")) a7<-get(paste(a,".7",sep="")) b<-(w%in%a2|%in%a7) factor(b,levels=c(F,T),labels=c(paste("non-",a,sep=""),a)) } q("e") Thx, M

    Read the article

  • Problem with variable argument function in C++

    - by Freezerburn
    I'm trying to create a variable length function (obviously, heh) in C++, and what I have right now works, but only for the first argument. If someone could please let me know how to get this working with all the arguments that are passed, I would really appreciate it. Code: void udStaticObject::accept( udObjectVisitor *visitor, ... ) { va_list marker; udObjectVisitor *i = visitor; va_start( marker, visitor ); while( 1 ) { i->visit_staticObject( this ); //the if here will always go to the break immediately, allowing only //one argument to be used if( ( i = va_arg( marker, udObjectVisitor* ) ) ) break; } va_end( marker ); } Based on my past posts, and any help posts I make in general, there is probably some information that I did not provide that you will need to know to help. I apologize in advance if I forgot anything, and please let me know what you need to know so I can provide the information.

    Read the article

  • Javascript global variable not working properly?

    - by Fabian
    My jQuery code: $(document).ready(function() { chrome.extension.sendRequest({get: "height"}, function(response) { height = response.value; }); $("#id").css("height", height+"px"); }); You don't have to be concerned about the chrome.extension.sendRequest(), basically it communicates with a background page to fetch the value for "height" from localStorage and stores the value in global variable height. The problem lies in $("#id") not being assigned the height value. However if I were to modify it such that it is now: $(document).click(function() { $("#id").css("height", height+"px"); }); it works. Any idea why?

    Read the article

  • jquery updating a div in ajax diesnt work properly, when using a variable

    - by maschek
    hi, i got the following code var zieldiv = $(this).attr(\'id\'); $.ajax({ url: \'index.php?params\', type: \'POST\', data: { color:thenewcolor, zieldiv:zieldiv }, timeout: 50000, beforeSend: function() { $("#" + zieldiv).css({background: "#" + thenewcolor} ); } }); I use this for dragging a small div into a bigger div. the variable at the beginnning would give out the string "test1". So in the ajax.thing the css of a div which matches the var zieldiv should be updatet. Problem is, if i would place a string instead a var into the $(...) like $("#test1") it acts like its supposed to, the #test1 gets updated. but if i use the var $("#" + zieldiv) the parent div, which is surrounding the #test1-div gets updated. but i know for sure the var zieldiv contains the string "test1", because when passing it to php it contains "test1". so i think this is a little strange. do you have any ideas? thanx, maschek

    Read the article

  • Returning a private variable in JavaScript

    - by enrmarc
    I don't know why console.log(Set.current_index) shows 0 instead of 3. var Set = (function() { var set = []; var index = 0; function contains(set, e) { for (var i = 0; i < set.length; i++) { if (set[i] === e) { return true; } } return false; } var add = function(e) { if (!contains(set, e)) { set[index++] = e; } } var show = function() { for (var i = 0; i < set.length; i++) { console.log(set[i]); } } return { add: add, show: show, current_index: index }; })();? Set.add(20); Set.add(30); Set.add(40); Set.show(); console.log(Set.current_index);

    Read the article

  • Pass variable number of variables to a class in PHP

    - by user325282
    I need to pass a variable number of strings to instantiate different classes. I can always do a switch on the size of the array: switch(count($a)) { case 1: new Class(${$a[0]}); break; case 2: new Class(${$a[0]}, ${$a[1]}); break; etc... There has to be a better way to do this. If I have an array of strings ("variable1", "variable2", 'variable3", ...), how can I instantiate a Class without manually accounting for every possibility?

    Read the article

  • Vew not updating after scope update

    - by bsparacino
    Here is a very simple example of what I am trying to do Athlete.save(athlete,function(result) { $scope.athlete = result.athlete; }); The issue is that the $scope.athlete variable does not update in my view. In order to get it to update I have to do this Athlete.save(athlete,function(result) { $scope.athlete.fname = result.athlete.fname; $scope.athlete.lname= result.athlete.lname; $scope.athlete.gender= result.athlete.gender; .... }); This gets annoying very quickly. With the first block of code it's as if angular does not know that my $scope.athlete variable has been updated. This function is triggered from an ng-click, not some jquery call, I am doing it the angular way as far as I know. here is a simpler case I made: http://plnkr.co/edit/lMCPbzqDOoa5K4GXGhCp

    Read the article

  • Why does this Rails named scope return empty (uninitialized?) objects?

    - by mipadi
    In a Rails app, I have a model, Machine, that contains the following named scope: named_scope :needs_updates, lambda { { :select => self.column_names.collect{|c| "\"machines\".\"#{c}\""}.join(','), :group => self.column_names.collect{|c| "\"machines\".\"#{c}\""}.join(','), :joins => 'LEFT JOIN "machine_updates" ON "machine_updates"."machine_id" = "machines"."id"', :having => ['"machines"."manual_updates" = ? AND "machines"."in_use" = ? AND (MAX("machine_updates"."date") IS NULL OR MAX("machine_updates"."date") < ?)', true, true, UPDATE_THRESHOLD.days.ago] } } This named scope works fine in development mode. In production mode, however, it returns the 2 models as expected, but the models are empty or uninitialized; that is, actual objects are returned (not nil), but all the fields are nil. For example, when inspecting the return value of the named scope in the console, the following is returned: [#<Machine >, #<Machine >] But, as you can see, all the fields of the objects returned are set to nil. The production and development environments are essentially the same. Both are using a SQLite database. Any ideas what's going wrong?

    Read the article

  • Why aren't variables declared in "try" in scope in "catch" or "finally"?

    - by Jon Schneider
    In C# and in Java (and possibly other languages as well), variables declared in a "try" block are not in scope in the corresponding "catch" or "finally" blocks. For example, the following code does not compile: try { String s = "test"; // (more code...) } catch { Console.Out.WriteLine(s); //Java fans: think "System.out.println" here instead } In this code, a compile-time error occurs on the reference to s in the catch block, because s is only in scope in the try block. (In Java, the compile error is "s cannot be resolved"; in C#, it's "The name 's' does not exist in the current context".) The general solution to this issue seems to be to instead declare variables just before the try block, instead of within the try block: String s; try { s = "test"; // (more code...) } catch { Console.Out.WriteLine(s); //Java fans: think "System.out.println" here instead } However, at least to me, (1) this feels like a clunky solution, and (2) it results in the variables having a larger scope than the programmer intended (the entire remainder of the method, instead of only in the context of the try-catch-finally). My question is, what were/are the rationale(s) behind this language design decision (in Java, in C#, and/or in any other applicable languages)?

    Read the article

  • How to create a variadic (with variable length argument list) function wrapper in JavaScript

    - by U-D13
    The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in a browser as well as in the Windows Script Host or other script engines. I am aware of 3 methods of which each one has its own drawbacks. eval() method: function wrapper () { var str = ''; for (var i=0; i<arguments.lenght; i++) str += (str ?', ':'') + ',arguments['+i+']'; return eval('[native_function] ('+str+')'); } switch() method: function wrapper () { switch (arguments.lenght) { case 0: return [native_function] (arguments[0]); break; case 1: return [native_function] (arguments[0], arguments[1]); break; ... case n: return [native_function] (arguments[0], arguments[1], ... arguments[n]); } } apply() method: function wrapper () { return [native_function].apply([native_function_namespace], arguments); } What's wrong with them you ask? Well, shall we delve into all the reasons why eval() is evil? And also all the string concatenation... Not a solution to be labeled "elegant". One can never know the maximum n and thus how many cases to prepare. This also would strech the script to immense proportions and sin against the holy DRY principle. The script could get executed on older (pre- JavaScript 1.3 / ECMA-262-3) engines that don't support the apply() method. Now the question part: is there any another solution out there?

    Read the article

  • Microsoft C Compiler: Inline variable declaration?

    - by Rosarch
    I'm writing C in Visual Studio 2010. The compiler doesn't seem to want to let me use inline variable declarations. The following code produces an error: unsigned int fibonacci_iterative(unsigned int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } unsigned int prev_prev = 0; // error unsigned int prev = 1; // error unsigned int next = 0; // error for (int term_number = 0; term_number < n; term_number++) { unsigned int temp = prev_prev + prev; prev = next; prev_prev = prev; next = temp; } return next; } Error: error C2143: syntax error : missing ';' before 'type' error C2143: syntax error : missing ';' before 'type' error C2143: syntax error : missing ';' before 'type' Why is this happening? Is there a setting to make the compiler not so strict?

    Read the article

  • Update table variable with function

    - by Joris
    I got a table variable @RQ, I want it updated using a table-valued function. Now, I think I do the update wrong, because my function works... The function: ALTER FUNCTION [dbo].[usf_GetRecursiveFoobar] ( @para int, @para datetime, @para varchar(30) ) RETURNS @ReQ TABLE ( Onekey int, Studnr nvarchar(10), Stud int, Description nvarchar(32), ECTSGot decimal(5,2), SBUGot decimal(5,0), ECTSmax decimal(5,2), SBUmax decimal(5,0), IsFree bit, IsGot int, DateGot nvarchar(10), lvl int, path varchar(max) ) AS BEGIN; WITH RQ AS ( --RECURSIVE QUERY ) INSERT @ReQ SELECT RQ.Onekey, RQ.Studnr, RQ.Stud, RQ.Description, RQ.ECTSGot, RQ.SBUGot, RQ.ECTSmax, RQ.SBUmax, RQ.IsFree, RQ.IsGot, RQ.DatumGot, RQ.lvl, RQ.path FROM RQ RETURN END Now, when I run a simple query: DECLARE @ReQ TABLE ( OnderwijsEenheid_key int, StudentnummerHSA nvarchar(10), Student_key int, Omschrijving nvarchar(32), ECTSbehaald decimal(5,2), SBUbehaald decimal(5,0), ECTSmax decimal(5,2), SBUmax decimal(5,0), IsVrijstelling bit, IsBehaald int, DatumBehaald nvarchar(10), lvl int, path varchar(max) ) INSERT INTO @ReQ SELECT * FROM usf_GetRecursiveFoobar(@para1, @para2, @para3) I got error: Msg 8152, Level 16, State 13, Line 20 String or binary data would be truncated. The statement has been terminated. Why? What to do about it?

    Read the article

  • Case Management In-Depth: Cases & Case Activities Part 1 – Activity Scope by Mark Foster

    - by JuergenKress
    In the previous blog entry we looked at stakeholders and permissions, i.e. how we control interaction with the case and its artefacts. In this entry we’ll look at case activities, specifically how we decide their scope, in the next part we’ll look at how these activities relate to the over-arching case and how we can effectively visualize the relationship between the case and its activities. Case Activities As mentioned in an earlier blog entry, case activities can be created from: BPM processes Human Tasks Custom (Java Code) It is pretty obvious that we would use custom case activities when either: we already have existing code that we would like to form part of a case we cannot provide the necessary functionality with a BPM process or simple Human Task However, how do we determine what our BPM process as a case activity contains? What level of granularity? Take the following simple BPM process Read the full article here. SOA & BPM Partner Community For regular information on Oracle SOA Suite become a member in the SOA & BPM Partner Community for registration please visit www.oracle.com/goto/emea/soa (OPN account required) If you need support with your account please contact the Oracle Partner Business Center. Blog Twitter LinkedIn Facebook Wiki Mix Forum Technorati Tags: ACM,BPM,Mark Foster,SOA Community,Oracle SOA,Oracle BPM,Community,OPN,Jürgen Kress

    Read the article

  • unit testing variable state explicit tests in dynamically typed languages

    - by kris welsh
    I have heard that a desirable quality of unit tests is that they test for each scenario independently. I realised whilst writing tests today that when you compare a variable with another value in a statement like: assertEquals("foo", otherObject.stringFoo); You are really testing three things: The variable you are testing exists and is within scope. The variable you are testing is the expected type. The variable you are testing's value is what you expect it to be. Which to me raises the question of whether you should test for each of these implicitly so that a test fail would occur on the specific line that tests for that problem: assertTrue(stringFoo); assertTrue(stringFoo.typeOf() == "String"); assertEquals("foo", otherObject.stringFoo); For example if the variable was an integer instead of a string the test case failure would be on line 2 which would give you more feedback on what went wrong. Should you test for this kind of thing explicitly or am i overthinking this?

    Read the article

  • How to ensure that a member variable is initialized before calling a class method

    - by Omkar Ekbote
    There's a class with a parametrized constructor that initializes a member variable. All public methods of the class then use this member variable to do something. I want to ensure that the caller always creates an object using the parametrized constructor (there is also a setter for this member variable) and then call that object's methods. In essence, it should be impossible for the caller to call any method without setting a value to the member variable (either by using the parametrized constructor or the setter). Currently, a caller can simply make an object using the default constructor and then call that object's method - I want to avoid checking whether or not the member variable is set in each and every one of the 20-odd methods of the class (and throw an exception if it is not). Though a runtime solution is acceptable (better than the one I mentioned above); a compile-time solution is preferable so that any developer will not be allowed to make that mistake and then waste hours debuggging it!

    Read the article

  • How do I resolve this scope issue in VB .NET?

    - by froadie
    I have a code structure something like this: For row = 1 To numRows Dim arrayIndex As Integer = 0 For column As Integer = bucketStartColumn To bucketEndColumn ' whatever code arrayIndex = arrayIndex + 1 Next Next Dim arrayIndex As Integer = 0 For column As Integer = bucketStartColumn To bucketEndColumn ' whatever code arrayIndex = arrayIndex + 1 Next Not exactly the code, so I don't really need suggestions about refactoring, but my problem is this - with this code I get a compiler error for the first Dim arrayIndex As Integer = 0 - "Variable 'arrayIndex' hides a variable in an enclosing block." As far as I can tell, arrayIndex is local to the first for loop and shouldn't exist by the time we reach the second loop. If I try to change the second declaration of arrayIndex to arrayIndex = 0, I get the error "Name 'arrayIndex' is not declared", as I expected. So is it visible, or not? Does this have something to do with the Dim keyword? Any suggestions of how to get around this, other than naming the second index variable something else?

    Read the article

  • Assign variable with variable in function

    - by freakazo
    Let's say we have def Foo(Bar=0,Song=0): print(Bar) print(Song) And I want to assign any one of the two parameters in the function with the variable sing and SongVal: Sing = Song SongVal = 2 So that it can be run like: Foo(Sing=SongVal) Where Sing would assign the Song parameter to the SongVal which is 2. The result should be printed like so: 0 2 So should I rewrite my function or is it possible to do it the way I want to? (With the code above you get an error saying Foo has no parameter Sing. Which I understand why, any way to overcome this without rewriting the function too much? Thanks in advance!

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >