Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In the following function is there a more elegant or best practice way to setState?
startStop(){
if(this.state.start === 'Start') startStop = 'Stop'
else startStop = 'Start'
this.setState({start:startStop})
}
for the flag, instead of string Start/Stop use true-false,
Eg:-
constructor(props){
this.state={
start:false
}
}
startStop(){
this.setState({start:!this.state.start})
}
render(){
return<Text>{this.state.start?'Running':'Stopped'}</Text>
}
If you had something like:
state = {
keepGoing: false,
}
Then you could do the following to toggle:
this.setState({ keepGoing: !this.state.keepGoing });
this.setState({start:this.state.start==='Start' ? 'Stop' : 'Start'})
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i am use datatables and jquery in vue and
> <script>
> export default {
> methods: {
> ddd() {
> alert(44444444);
> },
> },
> mounted: function () {
> let table = new DataTable("#tbl", {});
> $("#tbl tbody").on("click", "tr", function () {
> this.ddd();
> });
> },
> };
> </script>
why ddd() is not work please help me
Your issue is lexical scoping. the callback method you're provided is an anonymous function which redeclares the value of this. To solve it, use a fat arrow.
$("#tbl tbody").on("click", "tr", () => {
this.ddd();
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I use multi select DevExtreme DropdownBox in View and fill it from model
but I can't get selected values in controller on Post method
how I can read selected values?
I got a #Html.HiddenField then filled the hiddenfield value in below js function:
function getSelectedItemsKeys(items) {
var result = [];
items.forEach(function (item) {
if (item.selected) {
result.push(item.key);
}
if (item.items.length) {
result = result.concat(getSelectedItemsKeys(item.items));
}
});
$("#myHF").val(result);
return result;
}
then send hidden field to controller by view model.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Currently I'm using the yii2 array dataprovider for listing the datas from rest api. We have more than 10k records. Each rest api call can get only maximum 100 records, If we want more i need to give the limit and offset for this rest api call.
Is there any specific rest api dataprovider in yii2? else how can i implement pagination for this rest API?
dataprovider, in Yii2 has support for pagination. Suppose, your service receives it's params with the following code:
$params = Yii::$app->getRequest()->post();
You could include page parameter in the request, and then do a little hack (:P), like :
if (isset($params ['page'])) {
$_GET['page'] = (int) $params ['page'];
if ($_GET['page'] < 1) {
$_GET['page'] = 1;
}
}
Once you do that, your dataprovider automatically assigns the value of $_GET to it's result set. An example of dataprovider:
$dataProvider = new ActiveDataProvider([
'query' => Users::find(),
'pagination' => array('pageSize' => 10),
]);
Or, in your case:
$dataProvider = new ArrayDataProvider([
'allModels' => $query->from('post')->all(),
'sort' => [
'attributes' => ['id', 'username', 'email'],
],
'pagination' => [
'pageSize' => 10,
],
]);
To get the models, you could use getModels() method of dataprovider like following:
$models = $dataProvider->getModels();
Let me know if that solves your problem.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how to write html custom attribute in .less Use Mixins for example
[margin="2"]{margin:2px;}
You should explain why you want to use Less in this situation. Notice that Less only compiles static CSS.
You can use a Less mixin to dynamically built your CSS rules:
.createmargins(#i) {
& when (#i > 1) {
.createmargins(#i - 1);
}
[margin="#{i}"] { margin: unit(#i,px); }
}
.createmargins(100);
outputs:
[margin="1"] {
margin: 1;
}
[margin="2"] {
margin: 2;
}
[margin="3"] {
margin: 3;
}
and so on......
Demo: http://codepen.io/anon/pen/yyXEgg
The above possible generates a lot of unused CSS classes. Alternatively consider using jQuery (or jvascript) on DOM ready:
$("[margin]").each(function(){
$(this).css('margin',$(this).attr('margin') + 'px');
});
Demo: http://codepen.io/anon/pen/rawKjz
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
What Charting API / Tool is this?
http://wordpress.org/extend/plugins/multiple-post-thumbnails/stats/
The pie chart at least is an svg canvas inside of an iframe. i am confused what they are using, but I like it.
image http://img38.imageshack.us/img38/6513/picturets.png
google.load("visualization", "1", {packages: ["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
jQuery.getJSON('http://api.wordpress.org/stats/plugin/1.0/multiple-post-thumbnails?callback=?', function (data) {
draw_graph(data, 'version_stats', 'Active Versions');
});
}
function draw_graph(versions, id, title) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Version');
data.addColumn('number', 'Usage');
var count = 0;
jQuery.each(versions, function (key, value) {
if (Number(value) > 1) {
data.addRow();
data.setValue(count, 0, key);
data.setValue(count, 1, Number(value));
count++;
}
});
var chart = new google.visualization.PieChart(document.getElementById(id));
chart.draw(data, {width: 360, height: 240, title: title});
}
It looks like they are using Google's charting API: http://code.google.com/apis/chart/interactive/docs/index.html