问:
Vuejs reset fields after POST success callback
I'm having some problems resetting a textarea field after a POST request.
This is my component code

```<code><template lang="pug">
    .col-sm-12
        h2 Add new Task
        hr
        .form-group
            textarea.form-control(v-model="task.taskContent")
        .form-group
            button.btn.btn-primary(@click="createNewTask") Add Task
</template>

<script>
export default {
    data() {
        return {
            task: {
                taskContent: ''
            }
        };
    },
    methods: {
        createNewTask() {
            if (this.task.taskContent.length > 0) {

                // Sending data to the server
                this.$http.post('https://vue-taskmanager.firebaseio.com/task.json', this.task)
                .then(response => {
                    console.log(response);
                    // Adding the new task to the main template list
                    this.$emit('taskWasCreated', this.task);
                    // Resetting textarea content
                    this.task.taskContent = '';
                }, error => {
                    console.log(error);
                });

            } else {
                alert("Sorry you can't create an empty task");
            }

        }
    }
}
</script>
</code>```

This is the parent component

```<code><template lang="pug">
    .container
        .row
            app-newtask(@taskWasCreated="addTask")
            app-taskswrapper(:tasks="tasksArr")
            app-footer

</template>

<script>
import { EventBus } from './main.js';
import UserRegistration from './components/user/UserRegistration.vue';
import TasksWrapper from './components/TasksWrapper.vue';
import NewTask from './components/NewTask.vue';
import Footer from './components/Footer.vue';
export default {
    data() {
        return {
            tasksArr: [
                'Just something to see'
            ]
        };
    },
    methods: {
        addTask(task) {
            this.tasksArr.push(task)
        }
    },
    // Listening on Events from Task.vue
    created() {
        // Delete task from array
        EventBus.$on('taskWasDeleted', (taskIndex) => {
            this.tasksArr.splice(taskIndex, 1);
            // Delete task from db
            this.$http.delete('https://vue-taskmanager.firebaseio.com/task.json', this.task)
                .then(response => {
                        console.log(response);
                    }, error => {
                        console.log(error);
                    });
        });
        // Fetch tasks from db
        this.$http.get('https://vue-taskmanager.firebaseio.com/task.json')
            .then(response => {
                return response.json();
            })
            .then(task => {
                const resultsArray = [];
                for (let key in task) {
                    resultsArray.push(task[key]);
                }
                this.tasksArr = resultsArray;
            });
    },
    components: {
        'app-taskswrapper': TasksWrapper,
        'app-newtask': NewTask,
        'app-footer': Footer,
        'app-userregistration': UserRegistration
    }

}
</script>
</code>```

As you can see inside the response callback function I reset the task.taskContent value but the problem is that the string is sent to the db without problems while is not updated in the root component where I have an array storing all these strings.
I was thinking about using a watcher but I don't know if it's a good solution, do you have any suggestions?
Link to the github repo https://github.com/Polenj86/vue-taskmanager

答:
It's clear what is happening now that you've posted your parent component.

You are storing the task object in the parent's array. This is not going to be a copy of the task, it's going to be a reference of the same task that you are about to clear. So when you later set this.task.taskContent = '' you are changing the task in the parent array too.

Consider this:

```<code>var task_holder_array = []
var task = {name: "mark"}
task_holder_array.push(task)

console.log("array before: ", task_holder_array)

task.name = ""

console.log("array after: ", task_holder_array)
</code>```

You need to somehow create a new task object to push into the parent's array. There are a lot of ways you could do this. For example:

```<code>this.$emit('taskWasCreated', {name: this.task.name});
</code>```

Or you could just pass the task name string to the parent and let the parent create the object.

Body:
I'm having some problems resetting a textarea field after a POST request.
This is my component code

<template lang="pug">
    .col-sm-12
        h2 Add new Task
        hr
        .form-group
            textarea.form-control(v-model="task.taskContent")
        .form-group
            button.btn.btn-primary(@click="createNewTask") Add Task
</template>

This is the parent component

<template lang="pug">
    .container
        .row
            app-newtask(@taskWasCreated="addTask")
            app-taskswrapper(:tasks="tasksArr")
            app-footer

</template>

As you can see inside the response callback function I reset the task.taskContent value but the problem is that the string is sent to the db without problems while is not updated in the root component where I have an array storing all these strings.
I was thinking about using a watcher but I don't know if it's a good solution, do you have any suggestions?
Link to the github repo https://github.com/Polenj86/vue-taskmanager

Body:
It's clear what is happening now that you've posted your parent component.

You are storing the task object in the parent's array. This is not going to be a copy of the task, it's going to be a reference of the same task that you are about to clear. So when you later set this.task.taskContent = '' you are changing the task in the parent array too.

Consider this:

var task_holder_array = []
var task = {name: "mark"}
task_holder_array.push(task)

console.log("array before: ", task_holder_array)

task.name = ""

console.log("array after: ", task_holder_array)

You need to somehow create a new task object to push into the parent's array. There are a lot of ways you could do this. For example:

this.$emit('taskWasCreated', {name: this.task.name});

Or you could just pass the task name string to the parent and let the parent create the object.


来源: stackexchange

问:
How to setup error 404 page in Ruby on Rails system testing
Rails 5.1 introduced system testing that uses Capybara with Selenium to test the UI of Rails application.

I'm wondering to how to use this system testing to test the UI of error pages.

For standard controller tests, we can do something like below to assert response to be 404.

```<code>test 'should get not_found' do
  get errors_not_found_url
  assert_response :not_found
end
</code>```

But for system tests, if I go to a 404 page, exception will be thrown in controller level and tests terminate immediately without rendering the page.

```<code>test '404 page should render with the correct title' do
  # act.
  visit NOT_FOUND_URL

  # assert.
  assert_equal("#{APP_NAME} - #{TITLE_404}", page.title)
end
</code>```

Exception is thrown in controller level.

```<code>$ rails test test/system/error/error_page_test.rb
Run options: --seed 30076

# Running:

Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:55237
Use Ctrl-C to stop
2017-07-09 11:10:45 +1200: Rack app error handling request { GET /books/12345678 }
#<ActionController::RoutingError: Could not find book '12345678' by id or name>
/myapp/app/controllers/books_controller.rb:7:in `index'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/abstract_controller/base.rb:186:in `process_action'
...
</code>```

Under development/test environment, config.consider_all_requests_local can be set to false in order to show error page instead of stracktrace. But this doesn't swallow exception during system tests.

答:
If you don't want Capybara to re-raise server exceptions in the tests you can set Capybara.raise_server_errors = false.

Secondly, you should check your Gemfile and make sure any gems like web-console,better-errrors, etc are only loaded in the development environment (not in the test environment)

Finally, you shouldn't be using assert_equal with title, you should be using the Capybara provided assert_title which includes waiting/retrying behavior and will reduce potential flakiness in tests.

```<code>assert_title("#{APP_NAME} - #{TITLE_404}")
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Rails 5.1 introduced system testing that uses Capybara with Selenium to test the UI of Rails application.

I'm wondering to how to use this system testing to test the UI of error pages.

For standard controller tests, we can do something like below to assert response to be 404.

test 'should get not_found' do
  get errors_not_found_url
  assert_response :not_found
end

But for system tests, if I go to a 404 page, exception will be thrown in controller level and tests terminate immediately without rendering the page.

test '404 page should render with the correct title' do
  # act.
  visit NOT_FOUND_URL

  # assert.
  assert_equal("#{APP_NAME} - #{TITLE_404}", page.title)
end

Exception is thrown in controller level.

$ rails test test/system/error/error_page_test.rb
Run options: --seed 30076

# Running:

Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:55237
Use Ctrl-C to stop
2017-07-09 11:10:45 +1200: Rack app error handling request { GET /books/12345678 }
#<ActionController::RoutingError: Could not find book '12345678' by id or name>
/myapp/app/controllers/books_controller.rb:7:in `index'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/abstract_controller/base.rb:186:in `process_action'
...

Under development/test environment, config.consider_all_requests_local can be set to false in order to show error page instead of stracktrace. But this doesn't swallow exception during system tests.

Body:
If you don't want Capybara to re-raise server exceptions in the tests you can set Capybara.raise_server_errors = false.

Secondly, you should check your Gemfile and make sure any gems like web-console,better-errrors, etc are only loaded in the development environment (not in the test environment)

Finally, you shouldn't be using assert_equal with title, you should be using the Capybara provided assert_title which includes waiting/retrying behavior and will reduce potential flakiness in tests.

assert_title("#{APP_NAME} - #{TITLE_404}")


问:
I'm creating a table in in which the data is being gotten from a JSON file. this is the code
```<code>var myObj, i, t = document.querySelector("#data_table");

myObj = {
name: "John",
age: 30,
cars: [
{name: "Ford", models: ["Fiesta", "Focus", "Mustang"]},
{name: "BMW", models: ["320", "X3", "X5"]},
{name: "Fiat", models: ["500", "Panda"]}
]

};

for (i in myObj.cars) {
var _row = t.insertRow(-1);

var c = _row.insertCell(-1);
c.innerHTML = myObj.cars[i].name;
c.style.fontWeight = "bolder";

for (var j = 0; j < myObj.cars[i].models.length; j++) {
var _c = _row.insertCell(-1);
_c.innerHTML = myObj.cars[i].models[j];
}
}
</code>```

my problem now is the name of the cars are appear on in a single column instead of a row (e.g they should be the table header for each column). but i havent been able to figure it out. your help would be appreciated.

This is the html

```<code><table width='100%' id='data_table' class="table table-condensed table-hover">
<caption> VEHICLE DATA </caption>

</table>
</code>```

A link of what it looks like now
enter image description here

But this is what i want it to look like
enter image description here

答:
Hi I tested this and it works.  It will first add the names as the top row, then it will insert rows as needed and add the car types to the appropriate columns</p>

```<code><!DOCTYPE html>
<html>

<body>
<table width="100%" id="data_table" class="table table-condensed table-hover">
<caption> VEHICLE DATA </caption>

</table>
</script>
<script>

var myObj, i, t = document.querySelector("#data_table");

myObj = {
  name: "John",
  age: 30,
  cars: [
   {name: "Ford", models: ["Fiesta", "Focus", "Mustang"]},
   {name: "BMW", models: ["320", "X3", "X5"]},
   {name: "Fiat", models: ["500", "Panda"]}
  ]
};

var _row1 = t.insertRow(-1);
for (i in myObj.cars) {
  var c = _row1.insertCell(-1);
  c.innerHTML = myObj.cars[i].name;
  c.style.fontWeight = "bolder";
}

var topcount = 0;
for (i=0; i < myObj.cars.length; i++) {

  for (var j = 0; j < myObj.cars[i].models.length; j++) {
    if (topcount <= j) {
      var _row = t.insertRow(-1);
      topcount++;
      if(i > 0){
        for( var k = 0; k < i; k++){
          var _c = _row.insertCell(-1);
        }
      }
    } else {
      _row = t.rows[j+1];
    }
    var _c = _row.insertCell(-1);
    _c.innerHTML = myObj.cars[i].models[j];
  }

}

</script>

</body>
</html>
</code>```

Body:
var myObj, i, t = document.querySelector("#data_table");

myObj = {
name: "John",
age: 30,
cars: [
{name: "Ford", models: ["Fiesta", "Focus", "Mustang"]},
{name: "BMW", models: ["320", "X3", "X5"]},
{name: "Fiat", models: ["500", "Panda"]}
]

};

for (i in myObj.cars) {
var _row = t.insertRow(-1);

var c = _row.insertCell(-1);
c.innerHTML = myObj.cars[i].name;
c.style.fontWeight = "bolder";

for (var j = 0; j < myObj.cars[i].models.length; j++) {
var _c = _row.insertCell(-1);
_c.innerHTML = myObj.cars[i].models[j];
}
}

my problem now is the name of the cars are appear on in a single column instead of a row (e.g they should be the table header for each column). but i havent been able to figure it out. your help would be appreciated.

This is the html

 VEHICLE DATA

A link of what it looks like now
enter image description here

But this is what i want it to look like
enter image description here

Body:
Hi I tested this and it works.  It will first add the names as the top row, then it will insert rows as needed and add the car types to the appropriate columns

<!DOCTYPE html>
<html>

<body>
<table width="100%" id="data_table" class="table table-condensed table-hover">
<caption> VEHICLE DATA </caption>

</table>
</script>
<script>

var myObj, i, t = document.querySelector("#data_table");

myObj = {
  name: "John",
  age: 30,
  cars: [
   {name: "Ford", models: ["Fiesta", "Focus", "Mustang"]},
   {name: "BMW", models: ["320", "X3", "X5"]},
   {name: "Fiat", models: ["500", "Panda"]}
  ]
};

var _row1 = t.insertRow(-1);
for (i in myObj.cars) {
  var c = _row1.insertCell(-1);
  c.innerHTML = myObj.cars[i].name;
  c.style.fontWeight = "bolder";
}

var topcount = 0;
for (i=0; i < myObj.cars.length; i++) {

  for (var j = 0; j < myObj.cars[i].models.length; j++) {
    if (topcount <= j) {
      var _row = t.insertRow(-1);
      topcount++;
      if(i > 0){
        for( var k = 0; k < i; k++){
          var _c = _row.insertCell(-1);
        }
      }
    } else {
      _row = t.rows[j+1];
    }
    var _c = _row.insertCell(-1);
    _c.innerHTML = myObj.cars[i].models[j];
  }

}

</script>

</body>
</html>


问:
What is RevertToSelf()? - C#.net
I don't understand what RevertToSelf() does in a .net application. Checking MSDN definition it reads the definition as

```<code>The RevertToSelf function terminates the impersonation of a client application.
</code>```

So does the current user context changes to a sysadmin context by stopping client's context? By calling RevertToSelf() will my code run on sys admin mode?

Update

Okay so what happens if I call RevertToSelf() in an ASP.NET application? Let us consider I dont start any impersonation. So if I call RevertToSelf() will it revert to the application pool identity?

答: Assuming you have a certain user's credentials (ie. username and password), you can begin impersonation and make calls to the Win32 API that execute in the context of the impersonated user.  So you will have the the access rights of the user you are impersonating, UNTIL you call RevertToSelf(), in which case you will revert to the access rights of the user who originally launched the code.</p>

ContentLicense: CC BY-SA 2.5

Title: What is RevertToSelf()? - C#.net

Body:
I don't understand what RevertToSelf() does in a .net application. Checking MSDN definition it reads the definition as

The RevertToSelf function terminates the impersonation of a client application.

So does the current user context changes to a sysadmin context by stopping client's context? By calling RevertToSelf() will my code run on sys admin mode?

Update

Okay so what happens if I call RevertToSelf() in an ASP.NET application? Let us consider I dont start any impersonation. So if I call RevertToSelf() will it revert to the application pool identity?


问:
Android Studio doesn't see device
The AVD Manager in Android Studio doesn't show my device but adb devices does show it. Am I missing something obvious here?

答: Please see http://visualgdb.com/KB/usbdebug-manual/ as this worked well for me. Had to download and install the USB drivers inside Android studio then actually install the drivers via device manager  in windows 8.1</p>

ContentLicense: CC BY-SA 4.0

Title: Android Studio doesn't see device


问:
jstree: how can I sum values of selected nodes, whose direct parent is not selected?
See screenshots. I'm trying to sum the list prices of selected nodes whose direct parent is not selected. In the attached example, that sum would be 8.97 (2.62 + 0.29 + 0.29 + 0.29 + 0.29 + 2.57 + 2.62). Any suggestions?

Here's the HTML of the jstree div:

```<code>    <div aria-activedescendant="j1_7" aria-busy="false" aria-multiselectable="true" aria-selected="false" class="jstree jstree-1 jstree-default-dark jstree-default-dark-responsive jstree-checkbox-selection" id="MarketHierarchyContainer" role="tree" style="width:100%; margin-left:auto; margin-right:auto" tabindex="0">
        <ul class="jstree-container-ul jstree-children jstree-no-dots jstree-no-icons jstree-striped jstree-wholerow-ul" role="group">
            <li aria-expanded="true" aria-labelledby="j1_1_anchor" aria-level="1" aria-selected="false" class="jstree-node jstree-last jstree-open" id="j1_1" role="treeitem">
                <div class="jstree-wholerow" role="presentation">

                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_1_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">ALABAMA (OTHER) (market)</span><span style="margin-left:720px; position:absolute">46.70</span></a>
                <ul class="jstree-children" role="group" style="">
                    <li aria-expanded="true" aria-labelledby="j1_2_anchor" aria-level="2" aria-selected="false" class="jstree-node jstree-last jstree-open" id="j1_2" role="treeitem">
                        <div class="jstree-wholerow" role="presentation">

                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_2_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SRALABAMA (super region)</span><span style="margin-left:696px; position:absolute">12.12</span></a>
                        <ul class="jstree-children" role="group" style="">
                            <li aria-expanded="true" aria-labelledby="j1_3_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-open" id="j1_3" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_3_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BARBOUR (region)</span><span style="margin-left:681px; position:absolute">2.62</span></a>
                                <ul class="jstree-children" role="group" style="">
                                    <li aria-labelledby="j1_4_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_4" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_4_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BAKERHILL (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_5_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_5" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_5_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BLUE SPRINGS (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_6_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_6" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_6_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CLAYTON (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_7_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_7" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_7_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CLIO (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_8_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_8" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_8_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">EUFAULA (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_9_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf jstree-last" id="j1_9" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_9_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">LOUISVILLE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                </ul>
                            </li>
                            <li aria-expanded="true" aria-labelledby="j1_10_anchor" aria-level="3" aria-selected="false" class="jstree-node jstree-open" id="j1_10" role="treeitem">
                                <div class="jstree-wholerow" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_10_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CHEROKEE (region)</span><span style="margin-left:681px; position:absolute">2.62</span></a>
                                <ul class="jstree-children" role="group" style="">
                                    <li aria-labelledby="j1_11_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_11" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_11_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CEDAR BLUFF (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_12_anchor" aria-level="4" aria-selected="false" class="jstree-node jstree-leaf" id="j1_12" role="treeitem">
                                        <div class="jstree-wholerow" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_12_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CENTRE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_13_anchor" aria-level="4" aria-selected="false" class="jstree-node jstree-leaf" id="j1_13" role="treeitem">
                                        <div class="jstree-wholerow" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_13_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">GAYLESVILLE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_14_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_14" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_14_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">LEESBURG (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_15_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_15" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_15_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SAND ROCK (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_16_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf jstree-last" id="j1_16" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_16_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SPRING GARDEN (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                </ul>
                            </li>
                            <li aria-expanded="false" aria-labelledby="j1_17_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-closed" id="j1_17" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_17_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CULLMAN (region)</span><span style="margin-left:681px; position:absolute">2.57</span></a>
                            </li>
                            <li aria-expanded="false" aria-labelledby="j1_22_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-closed" id="j1_22" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_22_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">PIKE (region)</span><span style="margin-left:681px; position:absolute">2.62</span></a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</body>
</html>
</code>```

答:
Using Jquery and the javascript filter function, you could get all checked nodes and then filter just the elements whose parent is not checked yet.

var result = null;
$(function () {
 // items clicked inside SRALABAMA (super region)
 var clickedItems = $('li#j1_2 ul a.jstree-anchor.jstree-clicked');
   //console.log(clickedItems);

   result = clickedItems.filter(function(i, anchorElement){
    //console.log('anchorElement', anchorElement)

    var nodeID = anchorElement.id.replace('_anchor','');
    //console.log('nodeID',nodeID)

    var parentNode = $(anchorElement).parents('li.jstree-node').not('li#'+nodeID)[0]
    //console.log('parentNode',parentNode)

  if(parentNode){
   var parenIsClicked = $(parentNode).find('a.jstree-anchor').first().hasClass('jstree-clicked')
   //console.log('parenIsClicked',parenIsClicked)
  }

  // return the 'anchorElement' whose parent has not been clicked
    return !parenIsClicked
   });

   var sum = 0;
 for(var i = 0; i < result.length; i++){
  var spanWithPrice = $(result[i]).find('span').last();
  var price = parseFloat($(spanWithPrice).text());
  sum += price;
 }

 console.log(sum);
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
</head>
<body>
<div  aria-activedescendant="j1_7" aria-busy="false" aria-multiselectable="true" aria-selected="false" class="jstree jstree-1 jstree-default-dark jstree-default-dark-responsive jstree-checkbox-selection" id="MarketHierarchyContainer" role="tree" style="width:100%; margin-left:auto; margin-right:auto; display:none;" tabindex="0">
        <ul class="jstree-container-ul jstree-children jstree-no-dots jstree-no-icons jstree-striped jstree-wholerow-ul" role="group">
            <li aria-expanded="true" aria-labelledby="j1_1_anchor" aria-level="1" aria-selected="false" class="jstree-node jstree-last jstree-open" id="j1_1" role="treeitem">
                <div class="jstree-wholerow" role="presentation">

                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">ALABAMA (OTHER) (market)</span><span style="margin-left:720px; position:absolute">46.70</span>
                <ul class="jstree-children" role="group" style="">
                    <li aria-expanded="true" aria-labelledby="j1_2_anchor" aria-level="2" aria-selected="false" class="jstree-node jstree-last jstree-open" id="j1_2" role="treeitem">
                        <div class="jstree-wholerow" role="presentation">

                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SRALABAMA (super region)</span><span style="margin-left:696px; position:absolute">12.12</span>
                        <ul class="jstree-children" role="group" style="">
                            <li aria-expanded="true" aria-labelledby="j1_3_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-open" id="j1_3" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BARBOUR (region)</span><span style="margin-left:681px; position:absolute">2.62</span>
                                <ul class="jstree-children" role="group" style="">
                                    <li aria-labelledby="j1_4_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_4" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BAKERHILL (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_5_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_5" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BLUE SPRINGS (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_6_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_6" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CLAYTON (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_7_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_7" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CLIO (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_8_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_8" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">EUFAULA (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_9_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf jstree-last" id="j1_9" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">LOUISVILLE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                </ul>
                            </li>
                            <li aria-expanded="true" aria-labelledby="j1_10_anchor" aria-level="3" aria-selected="false" class="jstree-node jstree-open" id="j1_10" role="treeitem">
                                <div class="jstree-wholerow" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CHEROKEE (region)</span><span style="margin-left:681px; position:absolute">2.62</span>
                                <ul class="jstree-children" role="group" style="">
                                    <li aria-labelledby="j1_11_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_11" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CEDAR BLUFF (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_12_anchor" aria-level="4" aria-selected="false" class="jstree-node jstree-leaf" id="j1_12" role="treeitem">
                                        <div class="jstree-wholerow" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CENTRE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_13_anchor" aria-level="4" aria-selected="false" class="jstree-node jstree-leaf" id="j1_13" role="treeitem">
                                        <div class="jstree-wholerow" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">GAYLESVILLE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_14_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_14" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">LEESBURG (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_15_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_15" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SAND ROCK (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                    <li aria-labelledby="j1_16_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf jstree-last" id="j1_16" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SPRING GARDEN (zone)</span><span style="margin-left:657px; position:absolute">0.29</span>
                                    </li>
                                </ul>
                            </li>
                            <li aria-expanded="false" aria-labelledby="j1_17_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-closed" id="j1_17" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CULLMAN (region)</span><span style="margin-left:681px; position:absolute">2.57</span>
                            </li>
                            <li aria-expanded="false" aria-labelledby="j1_22_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-closed" id="j1_22" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">

                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">PIKE (region)</span><span style="margin-left:681px; position:absolute">2.62</span>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>

</body>
</html></code>```

Body:
See screenshots. I'm trying to sum the list prices of selected nodes whose direct parent is not selected. In the attached example, that sum would be 8.97 (2.62 + 0.29 + 0.29 + 0.29 + 0.29 + 2.57 + 2.62). Any suggestions?

Here's the HTML of the jstree div:

ALABAMA (OTHER) (market)46.70

SRALABAMA (super region)12.12

BARBOUR (region)2.62

BAKERHILL (zone)0.29

BLUE SPRINGS (zone)0.29

CLAYTON (zone)0.29

CLIO (zone)0.29

EUFAULA (zone)0.29

LOUISVILLE (zone)0.29

CHEROKEE (region)2.62

CEDAR BLUFF (zone)0.29

CENTRE (zone)0.29

GAYLESVILLE (zone)0.29

LEESBURG (zone)0.29

SAND ROCK (zone)0.29

SPRING GARDEN (zone)0.29

CULLMAN (region)2.57

PIKE (region)2.62

Body:
Using Jquery and the javascript filter function, you could get all checked nodes and then filter just the elements whose parent is not checked yet.

var result = null;
$(function () {
 // items clicked inside SRALABAMA (super region)
 var clickedItems = $('li#j1_2 ul a.jstree-anchor.jstree-clicked');
   //console.log(clickedItems);

   result = clickedItems.filter(function(i, anchorElement){
    //console.log('anchorElement', anchorElement)

    var nodeID = anchorElement.id.replace('_anchor','');
    //console.log('nodeID',nodeID)

    var parentNode = $(anchorElement).parents('li.jstree-node').not('li#'+nodeID)[0]
    //console.log('parentNode',parentNode)

  if(parentNode){
   var parenIsClicked = $(parentNode).find('a.jstree-anchor').first().hasClass('jstree-clicked')
   //console.log('parenIsClicked',parenIsClicked)
  }

  // return the 'anchorElement' whose parent has not been clicked
    return !parenIsClicked
   });

   var sum = 0;
 for(var i = 0; i < result.length; i++){
  var spanWithPrice = $(result[i]).find('span').last();
  var price = parseFloat($(spanWithPrice).text());
  sum += price;
 }

 console.log(sum);
});

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
</head>
<body>
<div  aria-activedescendant="j1_7" aria-busy="false" aria-multiselectable="true" aria-selected="false" class="jstree jstree-1 jstree-default-dark jstree-default-dark-responsive jstree-checkbox-selection" id="MarketHierarchyContainer" role="tree" style="width:100%; margin-left:auto; margin-right:auto; display:none;" tabindex="0">
        <ul class="jstree-container-ul jstree-children jstree-no-dots jstree-no-icons jstree-striped jstree-wholerow-ul" role="group">
            <li aria-expanded="true" aria-labelledby="j1_1_anchor" aria-level="1" aria-selected="false" class="jstree-node jstree-last jstree-open" id="j1_1" role="treeitem">
                <div class="jstree-wholerow" role="presentation">
                    &nbsp;
                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_1_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">ALABAMA (OTHER) (market)</span><span style="margin-left:720px; position:absolute">46.70</span></a>
                <ul class="jstree-children" role="group" style="">
                    <li aria-expanded="true" aria-labelledby="j1_2_anchor" aria-level="2" aria-selected="false" class="jstree-node jstree-last jstree-open" id="j1_2" role="treeitem">
                        <div class="jstree-wholerow" role="presentation">
                            &nbsp;
                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_2_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SRALABAMA (super region)</span><span style="margin-left:696px; position:absolute">12.12</span></a>
                        <ul class="jstree-children" role="group" style="">
                            <li aria-expanded="true" aria-labelledby="j1_3_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-open" id="j1_3" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                    &nbsp;
                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_3_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BARBOUR (region)</span><span style="margin-left:681px; position:absolute">2.62</span></a>
                                <ul class="jstree-children" role="group" style="">
                                    <li aria-labelledby="j1_4_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_4" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_4_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BAKERHILL (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_5_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_5" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_5_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">BLUE SPRINGS (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_6_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_6" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_6_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CLAYTON (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_7_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_7" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_7_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CLIO (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_8_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_8" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_8_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">EUFAULA (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_9_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf jstree-last" id="j1_9" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_9_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">LOUISVILLE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                </ul>
                            </li>
                            <li aria-expanded="true" aria-labelledby="j1_10_anchor" aria-level="3" aria-selected="false" class="jstree-node jstree-open" id="j1_10" role="treeitem">
                                <div class="jstree-wholerow" role="presentation">
                                    &nbsp;
                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_10_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox jstree-undetermined" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CHEROKEE (region)</span><span style="margin-left:681px; position:absolute">2.62</span></a>
                                <ul class="jstree-children" role="group" style="">
                                    <li aria-labelledby="j1_11_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_11" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_11_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CEDAR BLUFF (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_12_anchor" aria-level="4" aria-selected="false" class="jstree-node jstree-leaf" id="j1_12" role="treeitem">
                                        <div class="jstree-wholerow" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_12_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CENTRE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_13_anchor" aria-level="4" aria-selected="false" class="jstree-node jstree-leaf" id="j1_13" role="treeitem">
                                        <div class="jstree-wholerow" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor" href="#" id="j1_13_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">GAYLESVILLE (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_14_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_14" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_14_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">LEESBURG (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_15_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf" id="j1_15" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_15_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SAND ROCK (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                    <li aria-labelledby="j1_16_anchor" aria-level="4" aria-selected="true" class="jstree-node jstree-leaf jstree-last" id="j1_16" role="treeitem">
                                        <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                            &nbsp;
                                        </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_16_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">SPRING GARDEN (zone)</span><span style="margin-left:657px; position:absolute">0.29</span></a>
                                    </li>
                                </ul>
                            </li>
                            <li aria-expanded="false" aria-labelledby="j1_17_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-closed" id="j1_17" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                    &nbsp;
                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_17_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">CULLMAN (region)</span><span style="margin-left:681px; position:absolute">2.57</span></a>
                            </li>
                            <li aria-expanded="false" aria-labelledby="j1_22_anchor" aria-level="3" aria-selected="true" class="jstree-node jstree-closed" id="j1_22" role="treeitem">
                                <div class="jstree-wholerow jstree-wholerow-clicked" role="presentation">
                                    &nbsp;
                                </div><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" id="j1_22_anchor" tabindex="-1"><i class="jstree-icon jstree-checkbox" role="presentation"></i><i class="jstree-icon jstree-themeicon" role="presentation"></i><span style="position:absolute">PIKE (region)</span><span style="margin-left:681px; position:absolute">2.62</span></a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>

</body>
</html>


问:
Translating a Mysql Database Record Value into a PHP command
I have a field database record row that reads like this:

```<code>| id |  command  |
------------------
|  1 | getName() |
</code>```

I also have a PHP entity that is User, and has the getName() function.

Assuming the database record is read and parsed into $record and I have $user, how do I concatenate $record with the $user command?

I tried $user-> . $record['command'] but obviously does not work. I want to avoid hardcoding as I need it to be dynamic if possible.

Example of code:

```<code>$record = DB::queryFirstRow("SELECT * from command_records WHERE id='1'");
$user = new User("Kenny");
// Here is where I'm trying to perform the $user->getName()
// by reading $record['command']. $record['command'] is getName()
$user-> . $record['command'];
</code>```

It of course fails. I'm thinking of eval from googling earlier but can't get it to work out too.

答:
what you're looking for is PHP's variable variables

You can try something like:

```<code>class User
{
    public function getName()
    {
        return "SomeName";
    }
}

// assuming this is how your result looks like
$result = [
    'command' => 'getName()',
    // more data
];

$command = $result['command'];            // is "getName()"
$command = str_replace('()','',$command); // is "getName"
// you need to remove the '()'. just get the name of the method

$user = new User();
echo $user->{$command}();
// output: SomeName
</code>```

See it here: https://3v4l.org/OVYAa

Body:
I have a field database record row that reads like this:

| id |  command  |
------------------
|  1 | getName() |

I also have a PHP entity that is User, and has the getName() function.

Assuming the database record is read and parsed into $record and I have $user, how do I concatenate $record with the $user command?

I tried $user-> . $record['command'] but obviously does not work. I want to avoid hardcoding as I need it to be dynamic if possible.

Example of code:

$record = DB::queryFirstRow("SELECT * from command_records WHERE id='1'");
$user = new User("Kenny");
// Here is where I'm trying to perform the $user->getName()
// by reading $record['command']. $record['command'] is getName()
$user-> . $record['command'];

It of course fails. I'm thinking of eval from googling earlier but can't get it to work out too.

Body:
what you're looking for is PHP's variable variables

You can try something like:

class User
{
    public function getName()
    {
        return "SomeName";
    }
}

// assuming this is how your result looks like
$result = [
    'command' => 'getName()',
    // more data
];

$command = $result['command'];            // is "getName()"
$command = str_replace('()','',$command); // is "getName"
// you need to remove the '()'. just get the name of the method

$user = new User();
echo $user->{$command}();
// output: SomeName

See it here: https://3v4l.org/OVYAa


问:
Issue with right shift in PIG
I have a CSV file, which contains data in following fashion:

```<code>data_id,data_text,data_author
1,"here some text...",anurag
2,"Hi, i am apsc...",apsc
3,"i am living in "NYC"",another user
</code>```

I am doing following steps to load the correct data
approach 1.

```<code>temp = LOAD'filepath' USING PigStorage(',');
</code>```

when i am dumping temp, the data gets right shifted bcoz of an extra comma in 2nd record.

approach 2:
Loading data using new line as a delimiter

```<code>temp = LOAD'filepath' USING PigStorage('\n');
</code>```

it is giving me 1 record in 1 bag.

again i am trying to implement RegEx to break the bags

```<code>mydata = FOREACH data GENERATE FLATTEN(REGEX_EXTRACT_ALL('\\s*,\\s*,\\s*'));
</code>```

it is throwing error :

Pig Stack Trace

ERROR 1045:   Could not infer the matching function
  for org.apache.pig.builtin.REGEX_EXTRACT_ALL as multiple or none of
  them fit. Please use an explicit cast.

org.apache.pig.impl.logicalLayer.validators.TypeCheckerException:
  ERROR 1059:   Problem while reconciling output
  schema of ForEach     at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.throwTypeCheckerException(TypeCheckingRelVisitor.java:142)
    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:182)
    at
  org.apache.pig.newplan.logical.relational.LOForEach.accept(LOForEach.java:76)
    at
  org.apache.pig.newplan.DependencyOrderWalker.walk(DependencyOrderWalker.java:75)
    at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)    at
  org.apache.pig.PigServer$Graph.compile(PigServer.java:1635)   at
  org.apache.pig.PigServer$Graph.validateQuery(PigServer.java:1572)     at
  org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1544)     at
  org.apache.pig.PigServer.registerQuery(PigServer.java:516)    at
  org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:991)
    at
  org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:412)
    at
  org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:194)
    at
  org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:170)
    at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:69)  at
  org.apache.pig.Main.run(Main.java:538)    at
  org.apache.pig.Main.main(Main.java:157)   at
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:622)     at
  org.apache.hadoop.util.RunJar.main(RunJar.java:160) Caused by:
  org.apache.pig.impl.logicalLayer.validators.TypeCheckerException:
  ERROR 1045:   Could not infer the matching function
  for org.apache.pig.builtin.REGEX_EXTRACT_ALL as multiple or none of
  them fit. Please use an explicit cast.    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingExpVisitor.visit(TypeCheckingExpVisitor.java:775)
    at
  org.apache.pig.newplan.logical.expression.UserFuncExpression.accept(UserFuncExpression.java:88)
    at
  org.apache.pig.newplan.ReverseDependencyOrderWalker.walk(ReverseDependencyOrderWalker.java:70)
    at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visitExpressionPlan(TypeCheckingRelVisitor.java:191)
    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:157)
    at
  org.apache.pig.newplan.logical.relational.LOGenerate.accept(LOGenerate.java:246)
    at
  org.apache.pig.newplan.DependencyOrderWalker.walk(DependencyOrderWalker.java:75)
    at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:174)

  ... 19 more

Please help.

答:
You can use csvexcelstorage to load your data.You will have to download piggybank.jar and register it in your pigscript.</p>

```<code>REGISTER /path_to_jar/piggybank.jar;
DEFINE CSVExcelStorage org.apache.pig.piggybank.storage.CSVExcelStorage();

A = LOAD 'filepath/file.txt' USING CSVExcelStorage(',') AS (f1:int,f2:chararray,f3:chararray);
DUMP A;
</code>```

Title: Issue with right shift in PIG

Body:
I have a CSV file, which contains data in following fashion:

data_id,data_text,data_author
1,"here some text...",anurag
2,"Hi, i am apsc...",apsc
3,"i am living in "NYC"",another user

I am doing following steps to load the correct data
approach 1.

temp = LOAD'filepath' USING PigStorage(',');

when i am dumping temp, the data gets right shifted bcoz of an extra comma in 2nd record.

approach 2:
Loading data using new line as a delimiter

temp = LOAD'filepath' USING PigStorage('\n');

it is giving me 1 record in 1 bag.

again i am trying to implement RegEx to break the bags

mydata = FOREACH data GENERATE FLATTEN(REGEX_EXTRACT_ALL('\\s*,\\s*,\\s*'));

it is throwing error :

Pig Stack Trace

ERROR 1045:   Could not infer the matching function
  for org.apache.pig.builtin.REGEX_EXTRACT_ALL as multiple or none of
  them fit. Please use an explicit cast.

org.apache.pig.impl.logicalLayer.validators.TypeCheckerException:
  ERROR 1059:   Problem while reconciling output
  schema of ForEach     at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.throwTypeCheckerException(TypeCheckingRelVisitor.java:142)
    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:182)
    at
  org.apache.pig.newplan.logical.relational.LOForEach.accept(LOForEach.java:76)
    at
  org.apache.pig.newplan.DependencyOrderWalker.walk(DependencyOrderWalker.java:75)
    at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)    at
  org.apache.pig.PigServer$Graph.compile(PigServer.java:1635)   at
  org.apache.pig.PigServer$Graph.validateQuery(PigServer.java:1572)     at
  org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1544)     at
  org.apache.pig.PigServer.registerQuery(PigServer.java:516)    at
  org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:991)
    at
  org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:412)
    at
  org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:194)
    at
  org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:170)
    at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:69)  at
  org.apache.pig.Main.run(Main.java:538)    at
  org.apache.pig.Main.main(Main.java:157)   at
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:622)     at
  org.apache.hadoop.util.RunJar.main(RunJar.java:160) Caused by:
  org.apache.pig.impl.logicalLayer.validators.TypeCheckerException:
  ERROR 1045:   Could not infer the matching function
  for org.apache.pig.builtin.REGEX_EXTRACT_ALL as multiple or none of
  them fit. Please use an explicit cast.    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingExpVisitor.visit(TypeCheckingExpVisitor.java:775)
    at
  org.apache.pig.newplan.logical.expression.UserFuncExpression.accept(UserFuncExpression.java:88)
    at
  org.apache.pig.newplan.ReverseDependencyOrderWalker.walk(ReverseDependencyOrderWalker.java:70)
    at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visitExpressionPlan(TypeCheckingRelVisitor.java:191)
    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:157)
    at
  org.apache.pig.newplan.logical.relational.LOGenerate.accept(LOGenerate.java:246)
    at
  org.apache.pig.newplan.DependencyOrderWalker.walk(DependencyOrderWalker.java:75)
    at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)    at
  org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:174)

  ... 19 more

Please help.

Body:
You can use csvexcelstorage to load your data.You will have to download piggybank.jar and register it in your pigscript.

REGISTER /path_to_jar/piggybank.jar;
DEFINE CSVExcelStorage org.apache.pig.piggybank.storage.CSVExcelStorage();

A = LOAD 'filepath/file.txt' USING CSVExcelStorage(',') AS (f1:int,f2:chararray,f3:chararray);
DUMP A;


问:
Crontab to run a bash script that runs multiple python scripts
I'm a beginner in linux. I want run multiple python scripts every 30 second and I'm planning to do this using a bash script ( to run multiple python scripts simultaneously) and crontab (to schedule the scripts to run every 30 sec).

This is how my bash script:

```<code>#!/bin/bash
# This script is used to run multiple python script to query all types and all modes of GTFSR data

#Set working directory
cd "${0%/*}"

#BUS Query Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/buses' --database="postgresql://localhost/test" —apikey="XXX" -m "buses" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/buses' --database="postgresql://localhost/test" --apikey="XXX" -m "buses" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/buses' --database="postgresql://localhost/test" --apikey="XXX" -m "buses" -c -1 &

#Sydney Train Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &

#Ferries Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &

#lightrail Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &

#nswtrains Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
</code>```

This is what I put in crontab:

```<code># GTFSR to Database
* * * * * ( /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)
* * * * * ( sleep 30 ; /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)
</code>```

If I run /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call manually, the bash script works fine. However nothing happens when the job is run via CRONTAB.

Please help.

Cheers!

答:
it might be that the script, running from crontab, is lacking some environment variables that it needs in order to run properly.
see if this helps

it might be beneficial to redirect the bash output (both stdout and stderr) to a log file so that you can know why it failed

(a side note): putting sleep 30 in your cron definition sounds like a bad idea. why did you do that?

Body:
I'm a beginner in linux. I want run multiple python scripts every 30 second and I'm planning to do this using a bash script ( to run multiple python scripts simultaneously) and crontab (to schedule the scripts to run every 30 sec).

This is how my bash script:

#!/bin/bash
# This script is used to run multiple python script to query all types and all modes of GTFSR data

#Set working directory
cd "${0%/*}"

#BUS Query Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/buses' --database="postgresql://localhost/test" —apikey="XXX" -m "buses" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/buses' --database="postgresql://localhost/test" --apikey="XXX" -m "buses" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/buses' --database="postgresql://localhost/test" --apikey="XXX" -m "buses" -c -1 &

#Sydney Train Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/sydneytrains' --database="postgresql://localhost/test" --apikey="XXX" -m "sydneytrains" -c -1 &

#Ferries Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/ferries' --database="postgresql://localhost/test" --apikey="XXX" -m "ferries" -c -1 &

#lightrail Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/lightrail' --database="postgresql://localhost/test" --apikey="XXX" -m "lightrail" -c -1 &

#nswtrains Real Time
python gtfsrdb_tfnsw.py -p 'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
python gtfsrdb_tfnsw.py -t 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &
python gtfsrdb_tfnsw.py -a 'https://api.transport.nsw.gov.au/v1/gtfs/alerts/nswtrains' --database="postgresql://localhost/test" --apikey="XXX" -m "nswtrains" -c -1 &

This is what I put in crontab:

# GTFSR to Database
* * * * * ( /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)
* * * * * ( sleep 30 ; /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call)

If I run /bin/bash /home/amarinS/projects/TfNSW_GTFSRDB/GTFSR_call manually, the bash script works fine. However nothing happens when the job is run via CRONTAB.

Please help.

Cheers!


问:
Dynamic pages with Django & Celery
I have a Celery task registered in my tasks.py file. When someone POST to /run/pk I run the task with the given parameters. This task also executes other tasks (normal Python functions), and I'd like to update my page (the HttpResponse returned at /run/pk) whenever a subtask finishes its work.

Here is my task:

```<code>from celery.decorators import task

@task
def run(project, branch=None):
    if branch is None:
        branch = project.branch
    print 'Creating the virtualenv'
    create_virtualenv(project, branch)
    print 'Virtualenv created' ##### Here I want to send a signal or something to update my page
    runner = runner(project, branch)
    print 'Using {0}'.format(runner)
    try:
        result, output = runner.run()
    except Exception as e:
        print 'Error: {0}'.format(e)
        return False
    print 'Finished'
    run = Run(project=project, branch=branch,
                       output=output, **result._asdict())
    run.save()
    return True
</code>```

答:
With many years past since this question was asked, Channels is a way you could now achieve this using Django.

Then Channels website describes itself as a "project to make Django able to handle more than just plain HTTP requests, including WebSockets and HTTP2, as well as the ability to run code after a response has been sent for things like thumbnailing or background calculation."

Title: Dynamic pages with Django & Celery

Body:
I have a Celery task registered in my tasks.py file. When someone POST to /run/pk I run the task with the given parameters. This task also executes other tasks (normal Python functions), and I'd like to update my page (the HttpResponse returned at /run/pk) whenever a subtask finishes its work.

Here is my task:

from celery.decorators import task

@task
def run(project, branch=None):
    if branch is None:
        branch = project.branch
    print 'Creating the virtualenv'
    create_virtualenv(project, branch)
    print 'Virtualenv created' ##### Here I want to send a signal or something to update my page
    runner = runner(project, branch)
    print 'Using {0}'.format(runner)
    try:
        result, output = runner.run()
    except Exception as e:
        print 'Error: {0}'.format(e)
        return False
    print 'Finished'
    run = Run(project=project, branch=branch,
                       output=output, **result._asdict())
    run.save()
    return True


问:
How can I dismiss the on screen keyboard?
I am collecting user input with a TextFormField and when the user presses a FloatingActionButton indicating they are done, I want to dismiss the on screen keyboard.

How do I make the keyboard go away automatically?

```<code>import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  MyHomePageState createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  TextEditingController _controller = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.send),
        onPressed: () {
          setState(() {
            // send message
            // dismiss on screen keyboard here
            _controller.clear();
          });
        },
      ),
      body: new Container(
        alignment: FractionalOffset.center,
        padding: new EdgeInsets.all(20.0),
        child: new TextFormField(
          controller: _controller,
          decoration: new InputDecoration(labelText: 'Example Text'),
        ),
      ),
    );
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

void main() {
  runApp(new MyApp());
}
</code>```

答:
Note: This answer is outdated. See the answer for newer versions of Flutter.

You can dismiss the keyboard by taking away the focus of the TextFormField and giving it to an unused FocusNode:

```<code>FocusScope.of(context).requestFocus(FocusNode());
</code>```

Body:
I am collecting user input with a TextFormField and when the user presses a FloatingActionButton indicating they are done, I want to dismiss the on screen keyboard.

How do I make the keyboard go away automatically?

import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  MyHomePageState createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  TextEditingController _controller = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.send),
        onPressed: () {
          setState(() {
            // send message
            // dismiss on screen keyboard here
            _controller.clear();
          });
        },
      ),
      body: new Container(
        alignment: FractionalOffset.center,
        padding: new EdgeInsets.all(20.0),
        child: new TextFormField(
          controller: _controller,
          decoration: new InputDecoration(labelText: 'Example Text'),
        ),
      ),
    );
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

void main() {
  runApp(new MyApp());
}

Body:
Note: This answer is outdated. See the answer for newer versions of Flutter.

You can dismiss the keyboard by taking away the focus of the TextFormField and giving it to an unused FocusNode:

FocusScope.of(context).requestFocus(FocusNode());


问:
DIV element didn't fit to webpage length
I have this div element that I'm using as a second background to an images added to the body element but it never does work properly as the the bottom sides never match in length.
Here is a screenshot.

I did make it work once though but it always gets messed up when I modify any other elements.
I have the same problem with width too.
I hope you can help out because I'm stuck with this one.

My CSS:

```<code>html, body {
    height: 100 % ;
    width: 100 % ;
    margin: 0;
    padding: 0;
}
body {
    background: url('../images/choc1.jpg');
    font - family: arial,
    Myriad pro,
    sans serif;
    color: #1E1B1B;
    background-repeat: no-repeat;
    background-attachment: fixed;
    padding:0;
    margin:0;
}
# page {
        width: 1233.5 px;
        background - color: rgba(255, 255, 255, 0.7);
        position: absolute;
        margin - left: 60 px;
        margin - right: 0 px;
        margin - bottom: 0 px;
        padding: 0 px;
        min - height: 100 % ;
}
</code>```

My HTML:

```<code><body>
    <div id="page">
</div>
</code>```

答:
So I wrote up an example that should help you.

So you made the page div an absolute position element which makes it very difficult to place within other objects. Absolute is a positioning that ignores where everything else is and just gets placed. You should rarely/never use it for containers like this.

The real important line I added was margin: 0 auto; which puts it in the center (horizontally) of the parent container. (The container that it is inside) I also put padding on the body which pushes the page container in, rather than using margins.

You might also be able to view this codepen for a few hours: https://codepen.io/anon/pen/WOaEeJ

```<code>html
   {
     height:100%;
     width:1280px;
     margin:0;
     padding:0;
   }
   body
   {
     background: url('https://static1.squarespace.com/static/56d8bff4a3360ca940504574/t/5847038d3e00be622f3ce337/1481049003115/?format=1500w');
     font-family: arial,Myriad pro,sans serif;
     color:#1E1B1B;
     background-repeat: no-repeat;
     background-size: 100%;
     padding: 20px;
   }
   #page
   {
     width: 100%;
     height: 89%;
     background-color: rgba(255,255,255,0.7);
     margin: 0 auto;
     padding:0px;
    }
</code>```

Body:
I have this div element that I'm using as a second background to an images added to the body element but it never does work properly as the the bottom sides never match in length.
Here is a screenshot.

I did make it work once though but it always gets messed up when I modify any other elements.
I have the same problem with width too.
I hope you can help out because I'm stuck with this one.

My CSS:

html, body {
    height: 100 % ;
    width: 100 % ;
    margin: 0;
    padding: 0;
}
body {
    background: url('../images/choc1.jpg');
    font - family: arial,
    Myriad pro,
    sans serif;
    color: #1E1B1B;
    background-repeat: no-repeat;
    background-attachment: fixed;
    padding:0;
    margin:0;
}
# page {
        width: 1233.5 px;
        background - color: rgba(255, 255, 255, 0.7);
        position: absolute;
        margin - left: 60 px;
        margin - right: 0 px;
        margin - bottom: 0 px;
        padding: 0 px;
        min - height: 100 % ;
}

My HTML:

Body:
So I wrote up an example that should help you.

So you made the page div an absolute position element which makes it very difficult to place within other objects. Absolute is a positioning that ignores where everything else is and just gets placed. You should rarely/never use it for containers like this.

The real important line I added was margin: 0 auto; which puts it in the center (horizontally) of the parent container. (The container that it is inside) I also put padding on the body which pushes the page container in, rather than using margins.

You might also be able to view this codepen for a few hours: https://codepen.io/anon/pen/WOaEeJ

html
   {
     height:100%;
     width:1280px;
     margin:0;
     padding:0;
   }
   body
   {
     background: url('https://static1.squarespace.com/static/56d8bff4a3360ca940504574/t/5847038d3e00be622f3ce337/1481049003115/?format=1500w');
     font-family: arial,Myriad pro,sans serif;
     color:#1E1B1B;
     background-repeat: no-repeat;
     background-size: 100%;
     padding: 20px;
   }
   #page
   {
     width: 100%;
     height: 89%;
     background-color: rgba(255,255,255,0.7);
     margin: 0 auto;
     padding:0px;
    }