[英]How Can I Get The Value Of A Textfield From Database In Update Form
I'm using Yii framework Update form to get values from backend, I created a add/remove textfields feature in my form. 我正在使用Yii Framework Update表单从后端获取值,我在表单中创建了添加/删除文本字段功能。 I'm able to use the create form easily.
我可以轻松使用创建表单。 But, I have a problem in update form.
但是,我在更新表单时遇到问题。 Below is the code -
下面是代码-
$(function () {
var json = {
"welcomeList": ["Thanks for coming", "Please select from the following list", "dwadwadsds"],
"endList": ["Press come again", "Press 0"]
};
$.each(json.welcomeList, function (_, vv) {
$('<p><label for="p_scnts"><input type="text" class=cnt" size="20" name="p_scnt" value="' + vv + '"placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo('#p_scents');
});
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;
$('#addScnt').live('click', function () {
$('<p><label for="p_scnts"><input type="text" id="p_scnt_' + i + '" size="20" name="p_scnt_' + i + '" value="" placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function () {
if (i > 2) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
In the above code, I want to replace the hardcoded value of var json with the value from the database to the textfield. 在上面的代码中,我想用从数据库到文本字段的值替换var json的硬编码值。 How can I do this?
我怎样才能做到这一点?
You can do it like this, for example DefaultController 您可以这样做,例如DefaultController
public function actionIndex() {
//Here you can get data from DB
//and fill $result array, but I fill it manuallly
$result = array(
'welcomeList' => array(
"Thanks for coming",
"Please select from the following list",
"dwadwadsds"
),
'endList' => array(
"Press come again",
"Press 0"
)
);
echo json_encode($result);
Yii::app()->end();
}
Finally json hardcore in JS you can replace by this 最后JS中的json铁杆,您可以用此替换
var json = [];
$.getJSON( "/default", function( data ) {
json = data;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.