我被AngularJS和JSON卡住了。 我有一個名爲form.html的視圖,允許用戶選擇他們的省份。 我創建了省JSON文件並放入選擇標記,但是當我存儲MySQL時,我需要一個省編號 我在選項標記中嘗試了ng-value =「province.id」,但不起作用。當用戶選擇省時,我怎樣才能同時獲得pid(provinceId)?如何從AngularJS中的JSON中獲取屬性並選擇表格
province.JSON
[
{
"pid" : 1,
"name" : "Ontario"
},
{
"pid" : 2,
"name" : "Québec"
},
{
"pid" : 3,
"name" : "Nova Scotia"
},
{
"pid" : 4,
"name" : "New Brunswick"
},
...
form.html
<select name="province" ng-model="user.province" ng-required="true">
<option value="">--- Please select ---</option>
<option ng-repeat="province in provinces">{{province.name}}</option>
</select>
controllers.js
$scope.submitForm = function (user) {
dataObj = {
"name": user.name, //it works and all fine
"province": user.province, //it works and all fine
"telephone": user.telephone, //it works and all fine
"postalcode": user.postalcode, //it works and all fine
"salary": user.salary, //it works and all fine
"provinceId" : user.pid // undefine ..
}
和PHP的一部分是...? – Twinfriends
''? –
PHP有關係嗎?我認爲我的PHP是好的 – Jason