w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Deleting a dynamically allocated object inside of an object inside of an array
A very simple pattern: have the destructor of your tile objects delete their Interactable objects if they have them. That way deleting a tile cleans up automatically and you don't have to worry about this on the outside. Or use some type of smart pointer instead of a raw pointer for the objects referenced by your Tile class.

Categories : C++

Update collection erases all information inside
You'll want to take a look at the MongoDB documentation for updates found here: http://docs.mongodb.org/manual/reference/method/db.collection.update/#db.collection.update Specifically: Add New Fields db.bios.update( { _id: 3 }, { $set: { mbranch: "Navy", "name.aka": "Amazing Grace" } } ) Notice that in order to add a field, you need to use the $set operator Chris@MongoLab

Categories : PHP

Meteor: Embed documents inside a document or separate them into each collection object and link them?
Separate collections for students and classrooms seems more straightforward. I think just keeping a 'classroom' or 'classroomId' field in each student document will allow you to join the two collections when necessary.

Categories : Mongodb

how to loop through Json result object inside object array
I'd suggest that if your data is consistent, then you're better off working directly with the format and not looping through everything to find keys and values. I created a Fiddle using your code (skipping the AJAX part.) and for contrast another Fiddle with the following code: var success = function (data) { var product, i, len, $output = $('.resultJson'); for (i = 0, len = data.length; i < len; i++) { product = data[i]; console.log('Object: ' + i); var details = product.ProductDetails; var MSRP = product.ProductDetails.MSRP; var price = product.ProductDetails.Price; console.log(details); console.log(MSRP); console.log(price); $output.append("<br />"); $output.append("ProductId: " + product

Categories : Javascript

$.each inside $.append (Object [object Array] has no method 'apply')
No, you can't return from the iterator -- you have to keep a buffer that you fill, and return the buffer when all iterations are done. Something in the lines of; $('<div />').append(function () { var buffer = ""; $.each (parameterObject.rows, function () { buffer += "<div />"; }); return buffer; });

Categories : Javascript

How to display an image inside a User Control inside a Web Form using Byte Array?
Adding <img src="/imagehandler.ashx" /> and public class ImageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.OutputStream.Write(imageData, 0, imageData.Length); context.Response.ContentType = "image/JPEG"; } } another solution to this problem is to put the image data in cache: Guid id = Guid.NewGuid(); HttpRuntime.Cache.Add(id.ToString(), imageData); And pass the key to the HttpHandler in the querystring, so it can fetch it from cache: <img src="/imagehandler.ashx?img=<%=id%>" /> <!-- will print ...ashx?img=42a96c06-c5dd-488c-906f-cf20663d0a43 --> Reference: bytearray to image asp.net

Categories : C#

using a bash array inside a git filter command (i.e. inside quotation marks)
You're missing the braces that group the array name with the index, and for the sed command you need double quotes in order to have the shell variables expanded. old=${oldFSarray[$i]} new=${newFSarray[$i]} sed -i.bak "s/$old/$new/g" $newfs.xml

Categories : Bash

Getting a value from a JSON array inside an object
industryIdentifiers is an array so you will need to access it's elements by index, not by name: var industryIdentifiers = bookDetails.volumeInfo.industryIdentifiers; //get a reference to the array for brevity for(var i=0; i< industryIdentifiers.length; i++) { //loop through all industryIdentifiers var type = industryIdentifiers[i].type; //access industryIdentifiers by index if(type === 'ISBN_10') { //test if this is the ISBN_10 identifier $('#ISBN').text(type); } }

Categories : Jquery

How to watch for changes in collection objects inside custom collection
the item class has to implement INotifyPropertyChanged then you have two options: save the list (parent) in the child class (item) and on item propertychange you call a certain method or when you add an item to your list you add its NotifyPropertyChanged Event. I would go that way. List: public listclass() { this.ListChanged += new ListChangedEventHandler(listclass_ListChanged); } void listclass_ListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.ItemAdded) { item item = this[e.NewIndex]; item.PropertyChanged += new PropertyChangedEventHandler(Item_PropertyChanged); } } void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "propertyname") { } } item implements INo

Categories : C#

Perl array attribute inside an object
I see several problems here, but the most serious one is here: sub pushValidation() { my $validation = shift; push(@{$self->{_validation_array}}, $validation); }; This function is expecting a $self argument, but isn't shifting it from the arguments. You need to add use strict; at the top of your Perl file. If it had been enabled, the issue would have been immediately obvious: Global symbol "$self" requires explicit package name at <filename> line <line>. Same thing goes for the dump() function. (By the way, dump is a bad method name, as there is an (obscure) Perl builtin function with the same name. But that's not a huge issue.)

Categories : Perl

Get content from Array inside Object in a try-catch
See documentation. Class SoapFault is well documented. There are many methods. To access trace, use getTrace() method. http://php.net/manual/en/class.soapfault.php Try : try { WebServices::create($this->nameWS); } catch (Exception $e) { $tr = $e->getTrace(); var_dump($tr[3]); }

Categories : PHP

Parse xml inside xml object(with attribute) into array in cakephp
As far I know, everything you want to know you can find in the Cakebook: http://book.cakephp.org/2.0/en/core-utility-libraries/xml.html So you can parse XML into array as simple as: $xmlString = '<?xml version="1.0"?><root><child>value</child></root>'; // XML string $xmlArray = Xml::toArray(Xml::build($xmlString)); In the result your $xmlArray will have something like this: Array ( [root] => Array ( [child] => value ) )

Categories : Cakephp

Parsing JSON Object inside Array in Jackson
Maybe not the cleanest solution, but I tested it and it's working, using an Iterator for listes: ObjectMapper mapper = new ObjectMapper(); UserDetails userDetails = new UserDetails(); try { userDetails = mapper.readValue(fileReader, UserDetails.class); System.out.println(userDetails.getFirst_name()); System.out.println(userDetails.getLast_name()); List<User_user> users = new ArrayList<User_user>(); JsonNode rootNode = mapper.readTree(fileReader); JsonNode usersNode = rootNode.path("user_user"); Iterator<JsonNode> ite = usersNode.elements(); while (ite.hasNext()) { JsonNode temp = ite.next(); User_user user

Categories : Android

Accessing JSON array node inside an object
Here's some sample code that should help you. This prints out "data". package com.sandbox; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class Sandbox { public static void main(String[] args) throws JSONException { String input = "[ " + "{ " + " "dependencies": [ "data" " + " ] " + "} " + "]"; JSONArray start = new JSONArray(input); JSONObject jsonObject = start.getJSONObject(0); JSONArray dependencies = jsonObject.getJSONArray("dependencies"); String data = dependencies.getString(0); System.out.println(data); } } Here's my maven dependency: <dependency> <groupId>org.json<

Categories : Java

How to iterate inside an array of object containing multiple fields?
The result is List<Object[]>, so cast to that. So a list, where each element is an array of values. You must then cast each value to its type (which you know beforehand). If you simply want to iterate and print: List<Object[]> resultList = (List<Object[]>) query.getResultList(); for (Object[] array : resultList) { for (Object field : array) { System.out.println("->"+field); } } Alternatively, you can create a new class which has these exact fields, make its constructor accept all of the values, and use it in the query: SELECT new Foo(.....) FROM... There you can use the generic alternative of em.createQuery(..) that returns TypedQuery

Categories : Java

Bind a collection inside a collection in WPF combobox
well if you need each ComboBoxItem to display a collection of strings, use an ItemsControl in the ItemTemplate of ComboBox. <ComboBox ItemsSource="{Binding work}"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text={Binding a} /> <TextBlock Text={Binding b} /> <ItemsControl ItemsSource="{Binding c}" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>

Categories : C#

use "this" inside $.each inside object method
$.each is for looping over collections. What you are doing is looping over the letters in the string 'img'. You want to use .each; this is for jQuery objects. $('img').each(function(){ var width = $(window).width(), // this is a DOM element, we need to make it a jQuery object _this = $(this), alert(_this.attr('src')) });

Categories : Javascript

Page-up doesn't work inside bash inside conqueterm inside vim
Bind is a bash built-in command. It is nothing to do with vim. PgUp and PgDown is used by vim on the most usual way, and You cannot show bash command history in vim. Actually You can, but it seems to be pointless to me. If I know well the best place for key-bindings for bash is the ~/.inputrc file. I added your lines to it "e[5~": history-search-backward "e[6~": history-search-forward And it works well! But the "standard" way is the up and down arrow for these. Please describe what is your goal! ConqueTerm interprets "e" (escape) before bash does. This is why this would not work.

Categories : Bash

Backbone Collection inside Collection
The method is Available in the DesignModel and not in DesignCollection So when you call this method, it searches for the method inside the Collection which is not present that leads to the error. Also why do you want to bind the events using jQuery when you have an option of handing the same using Native Backbone events To solve this add the method to the collection define(['backbone', 'models/design'], function(Backbone, DesignModel){ var designCollection = Backbone.Collection.extend({ model: DesignModel, addElement: function(element, options) { return this.add(element, options); } }); return designCollection; });

Categories : Jquery

Array Declared inside method makes a difference in time from an array Declared outside a method and used inside as an input
I have a hunch - but it's only a hunch, and it's still surprising. This is a relatively long-running method - so Hotspot will probably JIT-compile it multiple times, applying more and more optimization. The bytecode for your first method is pretty short, so JITting it is quick. However, the byte code for your second method will be huge - and this may mean that most of the time is spent JITting. You could verify this by running each method multiple times, and printing out how long each iteration takes - I'd expect the "late" runs of each method to take about the same amount of time. Again, I'd be surprised if this accounted for all the difference (I'd expect the JIT to optimize the initialization bytecode once and then ignore it after that) but it's at least worth testing.

Categories : Java

How to update item inside an embedded array without adding a new item in Parse
Before replace value of your array make sure you have NSMutableArray (mutable) ? Otherwise you get error: Yes i have NSMutableArray then follow my suggestion: (Here i give simple basic logic) For replace any value at specific Index of NSMutableArray, UsereplaceObjectAtIndex:withObject:. For Example [MyArrayName replaceObjectAtIndex:0 withObject:MyValues]; Apply this logic:

Categories : IOS

what is the best way to create document inside collection in MongoDB
Two main considerations in data modelling for document stores: how data will grow and change over time, and the kinds of queries your application will perform. You have provided info around how data is expected to grow. Just on that basis, I would suggest option #1. { "member_id: 1" , "content_id: 10" , "activity_id: 1" } But, it is also important to understand what kind of queries you will be performing and how you intend to use this data in your application. Additional options possible are: one document per member with an array of feeds in each grouping documents by content or activity id, if that is how your application would query the data. So in summary, to come up with an optimal model, answering question 2 above is also important. PS: Option 2 in your question definite

Categories : PHP

Binding of a Collection nested inside a Model
I did it like this: // Tipo Caratteristica app.AttributeCategory = Backbone.Model.extend({ defaults: { name: '' }, initialize: function(options) { this.set('attributes', new app.Attributes(options.attributes)); Backbone.Model.prototype.apply(this, arguments); } }); But better use RationalModel for set up relations betweens models

Categories : Backbone Js

Why the queries inside the system.profile collection are being overwritten
system.profile is a capped collection with default size of 1MB so documents are purged on natural (with respect to insertion timestamp) basis in order to make room for newer documents. In order to increase the size of system.profile collection (say 10 MB) do: 1) Stop profiler : db.setProfilingLevel(0) 2) Drop system.profile: db.system.profile.drop() 3) Create a much larger system.profile collection manually: db.createCollection( "system.profile", { capped: true, size: 1024 * 1024 * 10 } ) 4) Enable profiling again If, on average, a 1MB collection fitted around 200-300 documents, the new settings will fit approximately 2,000 - 3,000 documents. Increase the system.profile size as needed.

Categories : Mongodb

ASP.NET MVC show collection of data in View inside of TextArea
In you .cshtml view, you can access data using @Model Now, since you have a list, I'd recommend you join it and then assign it to TextArea like @{var strList = string.Join(" ", Model)} @Html.TextArea("myTextArea",strList)

Categories : Asp Net Mvc

failed to lazily initialize a collection when inside a transaction
You have two problems in your code. First, you're passing a detached entity to a transactional service, and expect the entity to become attached automatically. That isn't the case, a detached entity is detached, and whether you're inside a transaction or not, trying to load some lazy property from a detached entity will lead to an exception. To load it, you would have to reload the entity, by ID, from the session, and then load the lazy collection from this attached entity. Second, you're assuming that getting the collection fro the entity loads it. That's not the case either. The collection is implemented as lazy-loaded proxy, and getting the collection and returning it does nothing more than getting the proxy (unitilialized) and returning it. It's only when calling a method on the coll

Categories : Spring

How to use an array inside a declaration of a new object from a class within a class?
On the face of it, you need to make it public: public void set(int l, int a, string[] sub_s, int[] sub_l) { ... Then, for each skill instance, you can call it: thievery.set( ... ); Where you want to call it, and with what parameter arguments, is up to you.

Categories : C#

Is it safe to add to a collection (mutable NSArray/NSDictionary) inside enumerateObjectWithBlock?
Is it safe to add to a NSMutableArray or NSMutableDictionary concurrently? Unless you provide your own synchronization mechanism which guarantees only one thread uses it at any given time, It is NOT safe. If you use it in a way that is not thread safe, you should expect undefined behavior.

Categories : Objective C

How do I get form_for(@example) to work inside my Collections#show when example belongs_to Collection
If Collection has many Examples then Example should be the one referencing Collection by id in the database: rails g migration AddCollectionIdToExamples collection_id:integer In CollectionsController#show, make sure you are instancing a new empty example to use in the form you are going to use: def show #stuff @example = @collection.examples.new

Categories : Ruby On Rails

Search inside an intmap collection for a specific attribute (not using map index)
What I usually do in this situation is build another index, e.g. db /click/by_qr : intmap(Scan.scan) or db /click/by_qr : intmap(int) // int represents user id Of course, this means you have to be careful to maintain the index. My understanding is that there will eventually be a better way to handle this, but right now you have to do it manually; I agree it's not a very nice solution.

Categories : Mongodb

How do I make a popover appear over a button inside a collection view protype cell
The second one crashes because an UIPopoverController needs to be a property or an instance variable, otherwise it will be deallocated on the end of the method, because the View that's showing it will not retain it

Categories : IOS

Oracle PL/SQL - Bulk Collection usage into WHERE and FROM clause inside conditions and inner views
TYPE t_bulk_vol is a PL/SQL type. That means you can only use it in PL/SQL constructs. You cannot use it in SQL, even if it's SQL in a PL/SQL program. If you want to use a nested table in the FROM clause of a SELECT you will need to define a SQL TYPE. This is a pain, because it means you can't use the %ROWTYPE definition (that's a PL/SQL only keyword). So you'll have to create an object whose signature matches the projection of the table, and then create nested table of that type. Find out more. Your cursor is defined wrongly. It should just be a SELECT statement. cursor cur is SELECT * FROM vol where ... ; Save the BULK COLLECT INTO l_vol for the actual fetch. Although presumably this is just a artefact of you faking some PL/SQL because you "cannot paste original code."

Categories : Oracle

Update property in object collection with linq
LINQ is not the right tool to modify collections, it is a tool to query collections. If you want to modify it you need a loop, for example a foreach: var schedule = data.Select(d => new Schedule{ ID = d.id }).ToList(); foreach(var s in schedule) s.Name = "Condition Name"; If you want to "modify" a collection with LINQ you have to create a new one and assign that to your variable which is inefficient.

Categories : C#

Update collection object using Underscore / Lo-dash
Give this a try: var exerciseIds = _(queryItems).pluck('ExerciseId').uniq().valueOf(); var item = { Exercise: null, ExerciseCategories: [] }; var exerciseAndCategories = []; //this part works fine _.forEach(exerciseIds, function (id) { var temp = _.findWhere(queryItems, { 'ExerciseId': id }); var newItem = _.clone(item); newItem.Exercise = temp.ExerciseId; exerciseAndCategories.push(newItem); }); //this is problem _.forEach(queryItems, function (i) { _(exerciseAndCategories).where({ 'Exercise': i.ExerciseId }).tap(function (x) { return _.forEach(x, function(item) { item.ExerciseCategories.push(i.ExerciseCategory); }); }).valueOf(); }); // exerciseAndCategories = [{"Exercise":1,"ExerciseCategories":["bik

Categories : Javascript

Fetch Subset of Backbone Collection with Unique Model URL (Code & Live Example Inside)
Your API doesn't seem RESTful, so you're probably causing yourself more trouble than necessary: Backbone expects a RESTful API by default. In any case, you need to do something like var Article = Backbone.Model.extend({ idAttribute: '_id' }); var ArticleCollection = Backbone.Collection.extend({ model: Article }); var Dog = Backbone.Model.extend({ idAttribute: '_id', initialize:function () { this.articles = new ArticleCollection({ url: "api/dogs/" + this.get('id'); }); } }); Then, you can do (e.g.): var doggy = new Dog({id: 51d0b9ad6fd59c5059000002}); doggy.articles.fetch(); var articlesForDoggy = doggy.articles; As a side node, why are you creating a new collection of dogs each time you instanciate a new dog model instance? Also to be noted: I would ser

Categories : Backbone Js

Entity Framework Update method to object with collection
Try this public void Update1(Recipe recipe) { if (recipe == null) return; var originalRecipe = DataContext.Recipes.FirstOrDefault(i => i.Id == recipe.Id); if (originalRecipe == null) return; originalRecipe.YOurPepertiNameToUpdate = recipe.YOurPepertiNameToUpdate ; originalRecipe.YOurPepertiNameToUpdate1 = recipe.YOurPepertiNameToUpdate1; originalRecipe.YOurPepertiNameToUpdate2 = recipe.YOurPepertiNameToUpdate2 ; DataContext.SaveChanges(); }

Categories : C#

Update and Add new Tag inside XML
Check these links which can help a lot (using linq is one of the best ways): add data to existing xml file using linq Adding element to XML using linq to XML Insert new XML node using LINQ As an example I just did: string customers = "<Customers><Customer Id="1" Name="abc"/><Customer Id="2" Name="efg"/></Customers>"; XDocument doc = XDocument.Parse(customers); XElement element = new XElement("Customer", new XAttribute("Id", "3"), new XAttribute("Name", "test")); doc.Element("Customers").Add(element); doc.Save(xmlfilepath); To Modify: var myElement = doc.Elements("Customers").Elements("Customer").Where(el => el.Attribute("Id").Value == "2").SingleOrDefault(); if (myElement != null) myElement.SetAttributeValue("Name", "aa

Categories : C#

Update xml elemnt inside function. How to pass elemnt inside function
What you are referring to is commonly know as pass by reference. When defining a function use the '&' sign for variables that you want to pass by reference. function showOrUpdate(&$element, $value) { if (isset($value) && !empty($value)) $element = $value; } This would update the original value of $element. Also, in this situation you don't need to use a return statement as the variable has already been modified within the function itself.

Categories : PHP

Ember-Data: RESTAdapter: It is possible to sideload an object list inside a sideloaded object?
Yes this is possible but it's not called sideloading - ember supports this technique but refers to it as embedded. So replace of the DS.RESTAdapter.configure {(.... sideLoadAs... try: DS.RESTAdapter.map('App.Flight', { flightDetails: { embedded: 'always' } }; Also since this is a hasMany relationship I would suggest changing your model definition to use the plural flightDetails: DS.hasMany('App.FlightDetail') instead of singular. See this SO post for another example of embedded hasMany relationships: How to make embedded hasMany relationships work with ember data

Categories : Rest

CSS absolute positioned object inside table-cell displayed object in Firefox
May be it's problem grow from this problem - Does Firefox support position: relative on table elements? And - Positioning context on table-cell element in Firefox Wrap the element with a div as position:relative. http://jsfiddle.net/N6bUU/2/ .rel { position:relative; display:block; height: 100%; width:100%; }

Categories : HTML



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.