json - Have Model Save as Modified Value -


This is a piece of code that I'm working with now:

  Lt; Ng-model = "rule.platforms" ng-options = "platform for platform in platform" name = "platform" multiple required & gt; & Lt; Option value = "" & gt; - platform - & lt; / Options & gt; & Lt; / Select & gt;   

The default behavior of multiple selections in angular pairing is to model an array, for example:

  rule.platforms = ["twitter", "google" ]   

However, because of how it should be saved in the database, all the values ​​must be added together in a string. Right now, it seems to be parsing the value before saving / saving, but due to this, a lot of logic will be added because it will be necessary to go through all the data and check each rule.

What I really want to do is, it is a means of changing how the ideal is started to bind into the model, so instead of the above it will be saved from this type of value: < pre> rule.platforms = "twitter, google"

Is this also possible? I am going on angular documentation but nothing like that has come. If anyone knows an easy way to get this behavior, please tell me!

** Edit **

To clarify the case of my specific use, I wanted to include the data structure in question: $ scope.data = {project: {name} ", subjects_right: [{name:" ", feed_size:" ", topic_sources_attributes: [{platform:" ", keyword:" ", Author: ""}], rules_overr: [{name: "", platform: "", conditional: "", word: ""}}}]}}}

this rule rules_attributes With rules and rules, there are rules_attributes and all its children have been dynamically created if it is a Rate Model parameter solution Mike suggested to work completely. Unfortunately, the dynamic nature of the model has made it difficult to change in the form of suggestions.

As far as I know the easiest way to achieve this is to create temporary scope for the platform Must use the variable Then you can see the temporal variables for changes with $ Watch, parse the price and update your rule. Platform with string value.

Edit: I thought that you are similar to this very simple approach:

  function MyCtrl ($ scope) {$ scope.rule = {} ; $ Scope.rule.platforms = ['google']; $ Scope.tempPlatforms = []; $ Scope.platforms = ['google', 'twitter']; ($ I $ scope.rule.platforms in var i) {$ scope.tempPlatforms [i] = $ scope.rule.platforms [i]; } $ Range $ Watch ('tempPlatforms', function (newview, old value) {$ scope.rule.platforms = newValue.join ();}); }   

If available platforms have been fixed then there should be no problem with updating the right rule. You can choose the selection within a single direction and binding on "=" or "& & amp; your needs, if the existing platforms are changed according to the existing rule, then it can be a bit tricky ...

Edit: I still can not believe that I understand this problem properly, but I have updated my Bela with a dynamic way of creating a new rule that I am going to help you How do I:

Originally I created an instruction for selection and added a $ radius. $ Watch ('rule', ...) reflects the dynamic change of the rules. / P>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -