Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

How to use a complex associative array in javascript? -


i need table http://code.google.com/apis/chart/docs/gallery/qr_codes.html#details in program , i'm not sure if associative array way go.

given type (numeric/alphanumeric), number of characters , ec (error correction) level, want function return version (first column).

first, javascript has "arrays" , "objects". 'associative array' assume mean javascript object, using keys other non-negative integers.

you can create javascript object literals using syntax such following:

var versions = {   "1" : {     rowcols : [21,21],     charsbyeclevel : {       l : {         digits:41,         alpha:25       },       m : {         digits:34,         alpha:20       }     }   },   "2" : {     rowcols : [25,25],     charsbyeclevel : {       l : {         digits:77,         alpha:47       },       m : {         digits:63,         alpha:48       }     }   } }; 

you access properties so:

console.log( versions[1].charsbyeclevel.l.digits ); // 41 

to loop through values, this:

function findversion( versions, level, digits ){   (var versionnumber in versions){     if (versions.hasownproperty(versionnumber)){       if (versions[versionnumber].charsbyeclevel[level].digits == digits){         return versionnumber;       }     }   } }  findversion( versions, "l", 77 ); // returns "2" 

edit: having written above, if only want versions based on level , digits, should reverse hash. instead of looping through , checking versions, index them directly , in constant time:

var versionbylevelanddigits = {   l : {      41 : 1,      77 : 2,     127 : 3   },   m : {      34 : 1,      63 : 2,     101 : 3   } };  var version = versionbylevelanddigits["l"][77]; // 2 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -