Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to add extra option?
Message
 
 
À
17/09/2014 04:32:03
Information générale
Forum:
Javascript
Catégorie:
Autre
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01607633
Message ID:
01607683
Vues:
50
>>Hi everybody,
>>
>>I have the following code:
>>
>>
>> var itemTrees = _itemTreeAdapter.GetAll().Select(it=> new {id = it.NodeId, Descrip = it.Descrip}).OrderBy(it=>it.Descrip);
>>
>>I want to add one extra option to that variable with id = 0 and Descrip = 'Select Item Tree...'
>>
>>I currently have the following code in my view:
>>
>>
>> <select class="form-control" ng-model="currentSalespoint.iTreeTop"
>>                            ng-options="t.id as t.descrip for t in metaData.itemTrees">
>>                        <option value="">Select Item Tree...</option>
>>                    </select>
>>
>>This sort of works, however, when I select that 'Select Item Tree...' option and try to save I immediately get the error on the form which looks like this (see attached). If I use 0 in the value, then this option is not shown up at all.
>>
>>So, I am thinking, perhaps there is a way to add this extra option in the list right away (and it should be sorted on top).
>>
>>Thanks in advance.
>
>Add it on the server?:
var xxx = _itemTreeAdapter.GetAll().Select(it=> new {id = it.NodeId, Descrip = it.Descrip}).OrderBy(it=>it.Descrip);
>var itemTrees = xxx.ToList();
>itemTrees.Insert(0, new { id = 0, Descrip = "Select Item Tree... " });
or in JavaScript:
metaDate.itemTrees.unshift({ id: 0, Descrip: 'Select Item Tree...' });
Hi Viv,

Thanks a lot, I'll try that. For some reason similar, but more complex code (as I read that unshift doesn't work in IE8) didn't work in JavaScript. The item was added OK, but it was not shown and I can not figure why.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform