Search Results

Search found 2536 results on 102 pages for 'nested'.

Page 27/102 | < Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >

  • Shorthand for nested null checking C#

    - by Myster
    As far as I know there is not a significantly more elegant way to write the following.... string src; if((ParentContent!= null) &&(ParentContent.Image("thumbnail") != null) &&(ParentContent.Image("thumbnail").Property("src") != null)) src = ParentContent.Image("thumbnail").Property("src").Value Do you think there should be a C# language feature to make this shorter? And if so, what should it look like? for example, something like extending the ?? operator string src = ParentContent??.Image("thumbnail")??.Property("width")??.Value; Apologies for the rather contrived example, and my over-simplified solution.

    Read the article

  • CakePHP Multiple Nested Joins

    - by Paul
    I have an App in which several of the models are linked by hasMany/belongsTo associations. So for instance, A hasMany B, B hasMany C, C hasMany D, and D hasMany E. Also, E belongs to D, D belongs to C, C belongs to B, and B belongs to A. Using the Containable behavior has been great for controlling the amount of information comes back with each query, but I seem to be having a problem when trying to get data from table A while using a condition that involves table D. For instance, here is an example of my 'A' model: class A extends AppModel { var $name = 'A'; var $hasMany = array( 'B' => array('dependent' => true) ); function findDependentOnE($condition) { return $this->find('all', array( 'contain' => array( 'B' => array( 'C' => array( 'D' => array( 'E' => array( 'conditions' => array( 'E.myfield' => $some_value ) ) ) ) ) ) )); } } This still gives me back all the records in 'A', and if it's related 'E' records don't satisfy the condition, then I just get this: Array( [0] => array( [A] => array( [field1] => // stuff [field2] => // more stuff // ...etc ), [B] => array( [field1] => // stuff [field2] => // more stuff // ...etc ), [C] => array( [field1] => // stuff [field2] => // more stuff // ...etc ), [D] => array( [field1] => // stuff [field2] => // more stuff // ...etc ), [E] => array( // empty if 'E.myfield' != $some_value' ) ), [1] => array( // ...etc ) ) When If 'E.myfield' != $some_value, I don't want the record returned at all. I hope this expresses my problem clearly enough... Basically, I want the following query, but in a database-agnostic/CakePHP-y kind of way: SELECT * FROM A INNER JOIN (B INNER JOIN (C INNER JOIN (D INNER JOIN E ON D.id=E.d_id) ON C.id=D.c_id) ON B.id=C.b_id) ON A.id=B.a_id WHERE E.myfield = $some_value

    Read the article

  • Creating a nested model form

    - by Elliot
    Hey Guys, I'm trying to build a multi model form - but one of the issues, is I need to link the models within the form. For example, lets say the form I have has the following models: Users, Profiles When creating a new user, I'd like to create a new profile simultaneously, and then link the two. The issue is, if neither have been created yet, they don't have ID's yet - so how can I assign linking values? Thanks! -Elliot

    Read the article

  • Creating a new nested resource

    - by Bobby B
    I'm working on a basic garden logging application which consists of gardens, plants and planted plants. Each user has one or many gardens, plants are master definitions, and a planted plant can be thought of as an instance of a plant in a specific user's garden. In my routes.rb file I have the following: map.resources :gardens do |gardens| gardens.resources :planted_plants, :has_many => :plant_log_entries, :collection => { :filter => :post, :choose_garden => :post} gardens.resources :garden_log_entries end map.resources :plants This makes sense to me when retrieving a list of planted_plants in a user's garden, but I'd like to create a planted_plant record from the index of plant. The problem is, a user can have multiple gardens. How can I create a new form for a planted_plant that allows the user to specify which garden should be used? The current route requires a garden_id - which makes sense for retrieval, but I'd like to supply that as a parameter for creation. Thanks in advance for any help!

    Read the article

  • Objective-C parse nested JSON string

    - by Matt S.
    I've tried everything (every method that shows up on a SO search), but I can't get it to work. I'm trying to parse this: questions = ( { owner = { "display_name" = "Neil"; }; title = "Initialising "; "up" = 11; "view" = 92; } ); I'm trying to get the display_name under owner.

    Read the article

  • AutoMapper and flattening nested arrays

    - by Bryan Slatner
    I'm trying to use AutoMapper to flatten multiple levels of arrays. Consider the following source classes: class X { public string A { get; set; } public Y[] B { get; set; } } class Y { public string C { get; set; } public Z[] D { get; set; } } class Z { public string E { get; set; } public string F { get; set; } } And the following destination: class Destination { public string A { get; set; } public string C { get; set; } public string E { get; set; } public string F { get; set; } } What I'd like to be able to do is get a List from one or more X, e.g.: Mapper.Map<IEnumerable<X>, IEnumerable<Destination>>(arrayOfX); I'm unable to figure out what sort of mapping configuration to use to achieve this. MapFrom seems like the way to go for 1:1 compositions, but doesn't seem to be able to handle the array (or other enumerable) unless I use AutoMapper's destination naming convention. Any insights on how to achieve this?

    Read the article

  • querying nested array elements in C#

    - by the berserker
    I have following object structure, deseralized from XML (WS): <ns2:Category> <ns2:CategoryId>800003</ns2:CategoryId> <ns2:CategoryName>Name1</ns2:CategoryName> <ns2:Categories> <ns2:Category> <ns2:CategoryId>800008</ns2:CategoryId> <ns2:CategoryName>Name2</ns2:CategoryName> <ns2:Categories> <ns2:Category> <ns2:CategoryId>800018</ns2:CategoryId> <ns2:CategoryName>Name3</ns2:CategoryName> <ns2:Categories/> </ns2:Category> <ns2:Category> <ns2:CategoryId>800028</ns2:CategoryId> <ns2:CategoryName>Name4</ns2:CategoryName> <ns2:Categories/> </ns2:Category> </ns2:Categories> </ns2:Category> <ns2:Category> <ns2:CategoryId>800009</ns2:CategoryId> <ns2:CategoryName>Name5</ns2:CategoryName> <ns2:Categories> <ns2:Category> <ns2:CategoryId>800019</ns2:CategoryId> <ns2:CategoryName>Name6</ns2:CategoryName> <ns2:Categories> <ns2:Category> <ns2:CategoryId>800119</ns2:CategoryId> <ns2:CategoryName>Name7</ns2:CategoryName> <ns2:Categories/> </ns2:Category> <ns2:Category> <ns2:CategoryId>800219</ns2:CategoryId> <ns2:CategoryName>Name111</ns2:CategoryName> <ns2:Categories/> </ns2:Category> </ns2:Categories> </ns2:Category> </ns2:Categories> </ns2:Category> </ns2:Categories> </ns2:Category> How would I find Category object with CategoryId 800119 efficiently? So, Im looking for something like FindCategory(long categoryId) - Prefferably with LINQ to objects. Any other option?

    Read the article

  • Rails model relations depending on count of nested relations

    - by Lowgain
    I am putting together a messaging system for a rails app I am working on. I am building it in a similar fashion to facebook's system, so messages are grouped into threads, etc. My related models are: MsgThread - main container of a thread Message - each message/reply in thread Recipience - ties to user to define which users should subscribe to this thread Read - determines whether or not a user has read a specific message My relationships look like class User < ActiveRecord::Base #stuff... has_many :msg_threads, :foreign_key => 'originator_id' #threads the user has started has_many :recipiences has_many :subscribed_threads, :through => :recipiences, :source => :msg_thread #threads the user is subscribed to end class MsgThread < ActiveRecord::Base has_many :messages has_many :recipiences belongs_to :originator, :class_name => "User", :foreign_key => "originator_id" end class Recipience < ActiveRecord::Base belongs_to :user belongs_to :msg_thread end class Message < ActiveRecord::Base belongs_to :msg_thread belongs_to :author, :class_name => "User", :foreign_key => "author_id" end class Read < ActiveRecord::Base belongs_to :user belongs_to :message end I'd like to create a new selector in the user sort of like: has_many :updated_threads, :through => :recipiencies, :source => :msg_thread, :conditions => {THREAD CONTAINS MESSAGES WHICH ARE UNREAD (have no 'read' models tying a user to a message)} I was thinking of either writing a long condition with multiple joins, or possibly writing giving the model an updated_threads method to return this, but I'd like to see if there is an easier way first. Any ideas? Also, if there is something fundamentally wrong with my structure for this functionality let me know! Thanks!!

    Read the article

  • nested foreach in PHP problem

    - by Neuquino
    I'm having problems to iterate twice on the same array: <? $indice=0 ?> <?php foreach ($comisiones as $comision1):?> <tr> <td><?php echo ++$indice ?></td> <td><?php echo tag('select',array('name'=>'comision_'.$indice),true)?> <?php foreach ($comisiones as $comision2):?> <option value="<?php echo $comision2->getId()?>"> <?php echo $comision2->getNombre()." - ".$comision2->getDescripcion()?> </option> <?php endforeach?> </select> </td> </tr> <?php endforeach?> The above code prints: And I'm expecting to see something like this (labels of the combos in the images are not the same, but I think the idea is clear): Thanks in advance

    Read the article

  • ASP.NET - Nested Custom Templates

    - by Echilon
    I'm thinking about converting a few usercontrols to use templates instead. One of these is my own UC which contains some controls, one of which is a repeater. Is it possible to specifcy a template for the second level usercontrol from the template for the first (which would be on the page)?

    Read the article

  • Zend Framework - applying order by on a nested query

    - by Gublooo
    Hey guys This might be a very simple thing. Check out the normal sql query below (select * from shopping order by shopping_id desc limit 5) order by RAND() This query runs successfully in mysql - not sure if this is the right way of doing it - but it works. It gets the last 5 ids from shopping table and randomly orders them everytime I want to achieve this in Zend. I'm not sure how to execute the first part and then apply the RAND clause to the results - what I have below does not do that. $select = $this-select() -from(array('sh'='shopping')) -order('shopping_id desc') -limit(5) -order('RAND()');

    Read the article

  • nested QMap in qt

    - by goutham
    I am trying to use this code in my QT app QMap<QString,QMap> but there is a build problem it says C:/****/****/****/***/domparser.h:14: error: type/value mismatch at argument 2 in template parameter list for 'template<class Key, class T> class QMap'

    Read the article

  • Sorting nested hash in ruby

    - by Rabbott
    Provided the following ruby hash: { cat: { 1: 2, 2: 10, 3: 11, 4: 1 }, wings: { 1: 3, 2: 5, 3: 7, 4: 7 }, grimace: { 1: 4, 2: 5, 3: 5, 4: 1 }, stubborn: { 1: 5, 2: 3, 3: 7, 4: 5 } } How can I sort the hash by the sum of 'leaf' excluding "4", for instance the value to compare for "cat" would be (2 + 10 + 11) = 23, the value for "wings" would be (3 + 5 + 7) = 15 so if I was comparing just those two they would be in the correct order, highest sum on top. It is safe to assume that it will ALWAYS be {1: value, 2: value, 3: value, 4: value} as those are keys for constants I have defined. It is also safe to assume that I will only ever want to exclude the key "4", and always use the keys "1", "2", and "3"

    Read the article

  • compareTo and nested Enums

    - by echox
    Hi, in "A Programmers Guide to Java SCJP Certification" I found an example which I can't follow. This the given enum: enum Scale3 { GOOD(Grade.C), BETTER(Grade.B), BEST(Grade.A); enum Grade {A, B, C} private Grade grade; Scale3(Grade grade) { this.grade = grade; } public Grade getGrade() { return grade; } } This is the given expression: Scale3.GOOD.getGrade().compareTo(Scale3.Grade.A) > 0; I don't understand why this expression will be true? The return value will be 2. compareTo() will return a value 0 if the given object is "less" than the object. Scale3.Grade.A is the "biggest" element of Grades, its ordinal number is 0. Scale3.GOOD is the "biggest" element of Scale3, its ordinal number is also 0. The constructor of Scale3 is called with Scale3.Grade.C, which ordinal number is 2. So the given expression is equal to the following code: Scale3.Grade.C.compareTo(Scale3.Grade.A) > 0; A is "bigger" than C, so shouldn't be the result < 0?

    Read the article

  • How to extract nested tar.gz files easily?

    - by StarCub
    Hi, I need to extract tar.gz a file. It's about 950mb. It has another 23 tar.gz files in it. Each of those 23 tar.gz files has one tar file in them. My questions is how I can easily extract all of them? Is there a commandline tool that I can use? The structure is like the following: foo.tar.gz +---bar1.tar.gz ¦ +---foobar1.tar +---bar2.tar.gz ¦ +---foobar2.tar +---bar3.tar.gz ¦ +---foobar3.tar +---bar4.tar.gz ¦ +---foobar4.tar +---bar5.tar.gz ¦ +---foobar5.tar +---bar6.tar.gz ¦ +---foobar6.tar | .......... | .......... | .......... | 23 of them Thanks in advance.

    Read the article

  • Getting text values of li (even nested) in JQuery

    - by Tahir Akram
    Hi; <ul> <li class="item-i">AI</li> <li class="item-ii">AII <ul class="level-2"> <li class="item-a">A</li> <li class="item-b">B</li> <li class="item-c">C</li> </ul> </li> <li class="item-iii">III</li> </ul> How can I get values AI AII A B C III? What I tried so far is following: $(document).ready(function() { $('li').each(function(index) { alert($(this).text()); }); }); But it does not gave me required results. When it reaches "item-ii" it gave all result. I want item one by one.

    Read the article

  • Return nested alias for linq expression

    - by Schotime
    I have the following Linq Expression var tooDeep = shoppers .Where(x => x.Cart.CartSuppliers.First().Name == "Supplier1") .ToList(); I need to turn the name part into the following string. x.Cart.CartSuppliers.Name As part of this I turned the Expression into a string and then split on the . and removed the First() argument. However, when I get to CartSuppliers this returns a Suppliers[] array. Is there a way to get the single type from this. eg. I need to get a Supplier back. Thanks

    Read the article

  • UICollectionViewController nested in a normal UIViewController

    - by patrickS
    I have added a UICollectionView into a normal ViewController (MainViewController), and than created a UICollectionViewController Subclass (CollectionViewController) in the ViewController and connected the UICollectionView outlet with the CollectionViewController object _collectionViewController = [[CollectionViewController alloc] initWithCollectionViewLayout:_collectionView.collectionViewLayout]; _collectionView.dataSource = _collectionViewController; _collectionView.delegate = _collectionViewController; In the CollectionViewController I have setup an simple NSArray object and I show this one. This works as expected. But If I try to access the collectionview from the CollectionViewController via self.collectionview I am not able to access this one. I dont know what I have to do, to also connect the collectionview. I have build a sample ios-app it is available at: https://github.com/patricks/uicollectionview-problem The method - (void)outputSelectedCell in the UICollectionViewController always shows, that there is nothing selected… I hope you understand the problem.

    Read the article

  • SVN: Nested repo

    - by Extrakun
    We are working with a PHP application which has no concept of switch-able themes; the situation is that we are modifying the application to add our own features, and CSS/Smarty templates for our own look and feel. We have 2 projects base on this application, each with a different layout/presentation. Hence I need to have one repo for the base application files, and one for the CSS/smarty templates. How should I go about doing this?

    Read the article

  • Python nested function scopes

    - by Thomas O
    I have code like this: def write_postcodes(self): """Write postcodes database. Write data to file pointer. Data is ordered. Initially index pages are written, grouping postcodes by the first three characters, allowing for faster searching.""" status("POSTCODE", "Preparing to sort...", 0, 1) # This function returns the key of x whilst updating the displayed # status of the sort. ctr = 0 def keyfunc(x): ctr += 1 status("POSTCODE", "Sorting postcodes", ctr, len(self.postcodes)) return x sort_res = self.postcodes[:] sort_res.sort(key=keyfunc) But ctr responds with a NameError: Traceback (most recent call last): File "PostcodeWriter.py", line 53, in <module> w.write_postcodes() File "PostcodeWriter.py", line 47, in write_postcodes sort_res.sort(key=keyfunc) File "PostcodeWriter.py", line 43, in keyfunc ctr += 1 UnboundLocalError: local variable 'ctr' referenced before assignment How can I fix this? I thought nester scopes would have allowed me to do this. I've tried with 'global', but it still doesn't work.

    Read the article

  • Modifying NSMutableDictionary from a single index format into nested (array within array)

    - by Michael Robinson
    I need to take the member ID off the top of this and create an array inside that contains the rest of the JSON return. Here is my JSON return. [{"F_Name_VC":"Frank", "L_Name_VC":"Johnson", "userid":"18", "age":"23", },] After it is json-deserialized it looks like this: I need convert it to be transformed into this, with children sub-array: Someone else posted a similar question but without the fact that it was coming from a JSON deserialization. There were two answers but no conclusion to the question. (Answer 1): NSDictionary *item1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@" member",[NSNumber numberWithInt:3],nil] forKeys:[NSArray arrayWithObjects:@"Title",@"View",nil]]; Answer (2): NSMutableArray *Rows = [NSMutableArray arrayWithCapacity: 1]; for (int i = 0; i < 4; ++i) { NSMutableArray *theChildren = [NSMutableArray arrayWithCapacity: 1]; [theChildren addObject: [NSString stringWithFormat: @"tester %d", i]]; NSString *aTitle = [NSString stringWithFormat: @"Item %d", i]; NSDictionary *anItem = [NSDictionary dictionaryWithObjectsAndKeys: aTitle, @"Title", theChildren, @"Children"]; [Rows addObject: anItem]; } NSDictionary *Root = [NSDictionary withObject: Rows andKey: @"Rows"]; Here is my JSON return and save code: NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; if (dict) { rowsArray = [dict objectForKey:@"member"]; [rowsArray retain]; } Thanks in advance. Every tutorial on JSON only shows a simple array being returned, never with children..It's driving me crazy trying to figure this out.

    Read the article

  • Setting nested object to null when selected option has empty value

    - by Javi
    Hello, I have a Class which models a User and another which models his country. Something like this: public class User{ private Country country; //other attributes and getter/setters } public class Country{ private Integer id; private String name; //other attributes and getter/setters } I have a Spring form where I have a combobox so the user can select his country or can select the undefined option to indicate he doen't want to provide this information. So I have something like this: <form:select path="country"> <form:option value="">-Select one-</form:option> <form:options items="${countries}" itemLabel="name" itemValue="id"/> </form:select> In my controller I get the autopopulated object with the user information and I want to have country set to null when the "-Select one-" option has been selected. So I have set a initBinder with a custom editor like this: @InitBinder protected void initBinder(WebDataBinder binder) throws ServletException { binder.registerCustomEditor(Country.class, "country", new CustomCountryEditor()); } and my editor do something like this: public class CustomCountryEditor(){ @Override public String getAsText() { //I return the Id of the country } @Override public void setAsText(String str) { //I search in the database for a country with id = new Integer(str) //and set country to that value //or I set country to null in case str == null } } When I submit the form it works because when I have country set to null when I have selected "-Select one-" option or the instance of the country selected. The problem is that when I load the form I have a method like the following one to load the user information. @ModelAttribute("user") public User getUser(){ //loads user from database } The object I get from getUser() has country set to a specific country (not a null value), but in the combobox is not selected any option. I've debugged the application and the CustomCountryEditor works good when setting and getting the text, thoughgetAsText method is called for every item in the list "countries" not only for the "country" field. Any idea? Is there a better way to set null the country object when I select no country option in the combobox? Thanks

    Read the article

  • Nested asynchronous calls do not seem to execute as expected

    - by Kristof Van Landschoot
    While trying out jQuery, I have a question that is probably a newbie mistake, but I cannot seem to find the solution. This is the code: $.get("index.html", function() { var i = 0; for (; i < 3; i++) { var lDiv = document.createElement('div'); lDiv.id = 'body-' + i; document.getElementById('body').appendChild(lDiv); $.get('index.html', function(data) { lDiv.innerHTML = "<p>Hello World " + i + "</p>"; }); } }); The output seems to be <div id='body-0'></div> <div id='body-1'></div> <div id='body-2'> <p>Hello World 3</p> </div> I expected the lDiv.innerHTML= code to be executed for each i, but apparently it is only executed for the last i? What am I overlooking?

    Read the article

  • How to clone only one of multiple nested elements

    - by eknown
    How do I find if the div I'm cloning has more than one of a child div with a certain class, and if so only clone one of them. Say the cloned div is .diseaseCon, and the child div(s) is .symptomCon, in the cloning action, how can I detect if there's more than one .symptomCon divs and only clone one if there are?

    Read the article

< Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >